我正在做一個項目,我正在使用GinAPI 開發框架和Firestore數據庫。在本地,一切正常。我能夠執行 CRUD 操作。當我將 API 部署到 時Heroku,我可以在日志中看到構建成功并且應用程序已部署。當我單擊它打開它時,它給出了錯誤"Application error"。這是因為 Heroku 沒有firestore從google-credentials.json文件中讀取我的憑據。而且我不應該上傳google-credentials.json文件,因為它有我的憑據。對于本地,我通過提供本地文件路徑來閱讀它??刂破?users.govar firestoreCredentialsLocation = "A:/Go/API_Gin/google-credentials.json" //local path to filefunc GetUses(c *gin.Context) { // Use a service account ctx := context.Background() sa := option.WithCredentialsFile(firestoreCredentialsLocation) app, err := firebase.NewApp(ctx, nil, sa) if err != nil { log.Fatalln(err) } client, err := app.Firestore(ctx) if err != nil { log.Fatalln(err) } defer client.Close() blah blah.......... blah blah.......... blah blah.......... } c.IndentedJSON(http.StatusOK, gin.H{ "message": "Users returned successfully!", })}點擊網址后報錯:錯誤日志:日志你們能告訴我如何解決這個問題嗎?我應該怎么做才能讓 Heroku 讀取我的數據庫憑據并成功部署應用程序?另外,告訴我給出 .json 文件的路徑是一個好方法嗎?謝謝你。
3 回答

嗶嗶one
TA貢獻1854條經驗 獲得超8個贊
問題解決了。我以不正確的方式讀取端口值,因此,應用程序崩潰了。Heroku 的 Go 應用程序文檔幫助了我。
https://devcenter.heroku.com/articles/getting-started-with-go

開心每一天1111
TA貢獻1836條經驗 獲得超13個贊
不要從文件中獲取憑據,而是嘗試從環境變量中獲取它們。您可以查看此 Heroku 文檔以了解如何在 Heroku https://devcenter.heroku.com/articles/config-vars中設置環境變量
- 3 回答
- 0 關注
- 242 瀏覽
添加回答
舉報
0/150
提交
取消