首頁 > 後端開發 > Golang > 主體

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

Barbara Streisand
發布: 2024-10-26 11:38:30
原創
481 人瀏覽過

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中文網其他相關文章!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!