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

Linda Hamilton
Release: 2024-10-26 07:52:30
Original
336 people have browsed it

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!