首頁  >  文章  >  後端開發  >  如何使用 Go 1.11 驗證 Google App Engine 標準中的私人 Go 模組?

如何使用 Go 1.11 驗證 Google App Engine 標準中的私人 Go 模組?

Barbara Streisand
Barbara Streisand原創
2024-10-26 11:38:30468瀏覽

How to Authenticate a Private Go Module in Google App Engine Standard with Go 1.11?

使用Go 1.11 在Google App Engine Standard 上驗證私有Go 模組

將Go App Engine Standard 專案移轉到Go 1.11 的模組時,開發人員可能會遇到私有模組的身份驗證問題。以下是解決gcloud 應用部署期間發生的「403 Forbidden」錯誤的方法:

問題

部署依賴於Bitbucket 上託管的私有模組的專案失敗,因為缺乏對私有儲存庫的身份驗證。

解決方案

不要在 Google Cloud Build 中設定直接存取私人儲存庫的憑證,而是考慮使用 Go 的模組替換功能。這會將 GAE 重定向為使用本機程式碼而不是遠端版本。

目錄結構

如下整理專案檔:

myService/
    src/
        service.go
        go.mod
    build/
        gae/
            src/        // simlink to ../../src
            modules/    // git ignored, contains cloned modules.
            app.go
            go.mod
            app.yaml

方法:

  1. 方法:
replace bitbucket.org/me/myService => ./src
replace bitbucket.org/me/myModule => ./modules/utils
    方法:

方法:

    方法:
  • 在build/gae/go.mod 中使用git module replacement 重定向GAE 使用本地程式碼:

建立一個建置腳本來解析myService/src/go. mod 以識別私有模組的正確版本並將其克隆到build/gae/modules 資料夾中。
優點私有模組包與 GAE 無關,使其能夠為其他環境(例如 docker)建置。 透過依賴Go 的模組系統簡化依賴管理.缺點如果私有模組依賴其他私有模組,可能會出現複雜性。

以上是如何使用 Go 1.11 驗證 Google App Engine 標準中的私人 Go 模組?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn