Home >Backend Development >Golang >How to Authenticate Private Go Modules in Google App Engine Standard with Go 1.11?

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

Linda Hamilton
Linda HamiltonOriginal
2024-10-26 07:52:30417browse

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

Authenticating Private Go Modules in Google App Engine Standard with Go 1.11

When updating a Go App Engine Standard project to Go 1.11 modules, authentication for private modules can pose a challenge. By default, the Google Cloud build system does not have access to private repositories.

The Error:

When attempting to deploy a project that includes private modules, an error similar to the following may occur:

ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build <GUI> 
status: FAILURE.
Build error details: go: bitbucket.org/[email protected]: 
https://api.bitbucket.org/2.0/repositories/myPrivateRepo?fields=scm: 
403 Forbidden

Can It Be Done?

Yes, it is possible to authenticate private modules in App Engine Standard using Go 1.11 modules. However, the migration documentation's guidance on moving files to the GOPATH is misleading. The new module system is indeed designed to keep code outside of the GOPATH.

Solution: Using Module Replace

Instead of managing credentials, a preferable solution is to use Go's module replace functionality. This allows the local project to use a local copy of the private module during the build.

Method:

  1. Create a build directory: Create a build directory within the main project directory.
  2. Symlink the source code: Link the src directory of the project into the src directory within the build directory.
  3. Clone or copy private modules: Clone or copy the necessary private modules into a subdirectory of the modules directory within build.
  4. Create a GAE-specific go.mod file: In the root of the build directory, create a new go.mod file that references the private module using the replace directive. For example:
module myServiceGAE

require (
    bitbucket.org/me/myService v0.0.0
    google.golang.org/appengine v1.4.0
)

replace bitbucket.org/me/myService => ./src
replace bitbucket.org/me/myModule => ./modules/utils

Pros:

  • Maintains separation of concerns between the project and GAE
  • Facilitates building the package for non-GAE environments

Cons:

  • May become complex if a private module depends on another private module

The above is the detailed content of How to Authenticate Private Go Modules in Google App Engine Standard with Go 1.11?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn