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条)

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了