首页  >  文章  >  后端开发  >  如何使用 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. 在 build/gae/go.mod 中使用 git module replacement 重定向 GAE 使用本地代码:
replace bitbucket.org/me/myService => ./src
replace bitbucket.org/me/myModule => ./modules/utils
  1. 创建一个构建脚本来解析 myService/src/go.mod 以识别私有模块的正确版本并将其克隆到 build/gae/modules 文件夹中。

优点

  • 私有模块包与 GAE 无关,使其能够为其他环境(例如 docker)构建。
  • 通过依赖 Go 的模块系统简化依赖管理.

缺点

  • 如果私有模块依赖于其他私有模块,可能会出现复杂性。

以上是如何使用 Go 1.11 验证 Google App Engine 标准中的私有 Go 模块?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn