dousi0144 2018-07-20 14:02
浏览 123
已采纳

构建包含Firebase凭证文件.json的golang

I've written an Golang program designed to is parse a scv file and upload data to FireStore, this program was build to share with people who just write scv path to upload info.

I'm using this to use firebase-admin:

opt := option.WithCredentialsFile("path/to/serviceAccountKey.json")

This approach works fine when I do:

$ go run main.go

but when I build the project and execute the binary I got this:

$ cannot read credentials file: open firebase-config.json: no such file or directory 

I did read this approach but it means share firebase-config.json too, the idea of this Go program is just share the executable without any doc else.

Is there a way to build the program including the json or authenticate firebase-admin using json directly like this?:

opt := option.WithCredentials({< authentication json >})

I have no found documentation or examples using this method WithCredential.

  • 写回答

2条回答 默认 最新

  • douqulv6059 2018-08-01 17:42
    关注

    I don't know if this is the best way to solve this but this is the way I did it:

    1. I decided to place this script executable into /opt/< dir-name >/bin
    2. I wrote an extra function which creates the auth .json /opt/< dir-name >/auth.json
    3. All the script executes using this /opt/< dir-name >/auth.json file
    4. I write another func which deletes the auth.json when the execution ends

    So, now I can do this:

    var file string = "/opt/< dir-name >/auth.json" 
    sa := option.WithCredentialsFile(file)
    

    Now I can share this script with the directive "Install into /opt/< dir-name>/bin and add this to your $PATH"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条