[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eThe Go buildpack defaults to the latest stable Go version, but you can specify a different version using the \u003ccode\u003eGOOGLE_GO_VERSION\u003c/code\u003e environment variable with a semver constraint.\u003c/p\u003e\n"],["\u003cp\u003eCompilation behavior can be configured via environment variables like \u003ccode\u003eGOOGLE_BUILDABLE\u003c/code\u003e to specify a buildable path, \u003ccode\u003eGOOGLE_CLEAR_SOURCE\u003c/code\u003e to omit source code, and \u003ccode\u003eGOOGLE_GOGCFLAGS\u003c/code\u003e/\u003ccode\u003eGOOGLE_GOLDFLAGS\u003c/code\u003e to pass custom flags.\u003c/p\u003e\n"],["\u003cp\u003eThe buildpack utilizes Go modules for dependency management, recommending the inclusion of a \u003ccode\u003ego.mod\u003c/code\u003e file in your application's root directory for module-aware mode.\u003c/p\u003e\n"],["\u003cp\u003eVendoring dependencies is supported by including a \u003ccode\u003evendor\u003c/code\u003e directory in the app's root, using the \u003ccode\u003ego build\u003c/code\u003e command to collect dependencies.\u003c/p\u003e\n"],["\u003cp\u003eYou can override the default application entrypoint (the compiled \u003ccode\u003emain\u003c/code\u003e executable) by providing a \u003ccode\u003eProcfile\u003c/code\u003e or using the \u003ccode\u003eGOOGLE_ENTRYPOINT\u003c/code\u003e environment variable.\u003c/p\u003e\n"]]],[],null,["# Building a Go application\n\nSpecifying the Go Version\n-------------------------\n\nBy default the Go buildpack uses the latest stable version of the Go compiler. If your application requires a specific version, you can use the `GOOGLE_GO_VERSION` environment variable to provide a semver constraint that will be used to select an available Go version. \n\n pack build sample-go --builder=gcr.io/buildpacks/builder \\\n --env GOOGLE_GO_VERSION=\"17.x.x\"\n\nCompilation Flags\n-----------------\n\nThe Go buildpack compiles your application source into an executable using the `go build command`. The following environment variables can be used to configure the build behavior:\n\n- `GOOGLE_BUILDABLE`\n Specifies path to a buildable unit.\n Example: `./maindir` for Go will build the package rooted at `maindir`.\n\n- `GOOGLE_CLEAR_SOURCE`\n Omit the source code from the application image. If the application depends on static files, such as Go templates, setting this variable may cause the application to misbehave.\n Example: `true`, `True`, `1` will clear the source.\n\n- `GOOGLE_GOGCFLAGS`\n Passed to `go build` and `go run` as `-gcflags` value with no interpretation.\n Example: `all=-N -l` enables race condition analysis and changes how source filepaths are recorded in the binary.\n\n- `GOOGLE_GOLDFLAGS`\n Passed to go build and go run as `-ldflags` value with no interpretation.\n Example: `-s -w` is used to strip and reduce binary size.\n\nManaging Dependencies\n---------------------\n\nWe recommend that you use [Go modules](https://go.dev/blog/using-go-modules) to manage dependencies in your Go app. The Go buildpack uses the `go build` command to build your app and therefore matches the behavior of Go itself. To ensure that your app uses module-aware mode, you should include a `go.mod` file in your application root.\n\n### Vendoring dependencies\n\nVendoring copies the packages your app uses into the application directory instead of downloading modules from their sources during the build process. Go provides the go build command [to vendor the packages your app needs](https://pkg.go.dev/cmd/go#hdr-Modules_and_vendoring) into a directory named `vendor` in your app's root directory.\n\nConfigure the Application Entrypoint\n------------------------------------\n\nBy default, the Go buildpack will configure the application container entry invoke the `main` executable produced when compiling your application source. If you need to override this, you can do so by providing a `Procfile` or passing the `GOOGLE_ENTRYPOINT` environment variable.\n\nEnvironment Variables\n---------------------\n\nThe Go buildpack supports the following environment variables to customize your container\n\n### GO\n\nSee Go documentation on [Environment Variables](https://pkg.go.dev/cmd/go#hdr-Environment_variables)\n\n**Example:** `GOFLAGS=-flag=value` passes `-flag=value` to `go` commands."]]