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 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办