App Engine 가변형 환경에서 실행 중인 인스턴스에 모든 linux/amd64 호환 패키지를 사용할 수 있습니다. 이 안내에서는 go get 명령어를 사용하여 지원되는 저장소(예: GitHub, Bitbucket, LaunchPad 등)에서 직접 패키지를 가져온다고 가정합니다.
Go 버전 1.22 이상부터 다음과 같은 사항이 적용됩니다.
기존 GOPATH 모드(GO111MODULE=off)의 모듈 외부에서 go get을 사용할 수 없습니다. 자세한 내용은 도구를 참조하세요.
Go에서는 종속 항목 관리에 go.mod 파일을 사용하는 것이 좋습니다. 배포 중에 종속 항목을 설치하려면 go.mod 파일을 app.yaml 파일과 동일한 폴더에 포함합니다. Go 버전과 공급업체 디렉터리의 종속 항목 관리 방법에 대한 자세한 내용은 GOPATH 및 모듈을 참조하세요.
종속 항목 선언 및 관리
Go 애플리케이션은 소스 파일의 디렉터리 구조를 그대로 반영한 패키지로 구성됩니다. import 문을 사용하면 가져오기의 상대 경로가 해석됩니다. 유효한 가져오기 경로는 GOPATH에서 지정된 모든 디렉터리의 src 하위 디렉터리를 기준으로 정규화된 경로입니다.
예를 들어 다음을 정의하는 앱 예시를 고려해 보세요.
GOPATH 모듈:
exportGOPATH=/home/fred/go.
src1-1.go 파일:
import"foo/bar"
gcloud CLI는 앱을 실행하거나 배포할 때 /home/fred/go/src/foo/bar 위치에서 foo/bar 패키지를 찾습니다.
GOPATH에 패키지 소스를 포함하는 경우 소스 코드를 app.yaml 파일이 위치한 앱 디렉터리 내에 배치하지 않도록 주의해야 합니다. 그렇지 않으면 패키지가 서비스 디렉터리를 기준으로 한 상대 경로에서 1번, 정규화된 경로에서 1번 등 총 2번 로드되어 미묘한 문제가 발생할 수 있습니다. 문제를 방지하기 위해 gcloud CLI는 앱의 디렉터리와 GOPATH를 모두 검사한 후 충돌이 감지되면 오류를 보고합니다.
최상의 결과를 얻으려면 다음 사항을 따르는 것이 좋습니다.
서비스마다 앱 디렉터리에 별도의 디렉터리를 만듭니다.
각 서비스의 디렉토리에는 서비스의 app.yaml 파일 및 하나 이상의 .go 파일이
있어야 합니다.
서비스 디렉터리에 하위 디렉터리를 포함하지 마세요.
GOPATH는 앱 디렉터리 외부에 있고 앱이 가져올 모든 종속 항목이 포함된 디렉터리를 지정해야 합니다.
필수 패키지 다운로드
go get 명령어를 사용하여 패키지를 다운로드할 수 있습니다. 예를 들어 GitHub my_repo에서 packagename을 다운로드하려면 다음 명령어를 실행합니다.
gogetgithub.com/my_repo/packagename
App Engine에 배포
애플리케이션을 App Engine에 배포하려면 애플리케이션 코드와 함께 앱에 필요한 라이브러리를 배포해야 합니다.
자세한 내용은 애플리케이션 테스트 및 배포를 참조하세요.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eApp Engine flexible environment supports any linux/amd64-compatible package, typically acquired using the \u003ccode\u003ego get\u003c/code\u003e command from repositories like GitHub and Bitbucket.\u003c/p\u003e\n"],["\u003cp\u003eGo version 1.22 and later restricts the use of \u003ccode\u003ego get\u003c/code\u003e outside of a module in the legacy \u003ccode\u003eGOPATH\u003c/code\u003e mode, with \u003ccode\u003eGO111MODULE\u003c/code\u003e set to \u003ccode\u003eoff\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eGo recommends using a \u003ccode\u003ego.mod\u003c/code\u003e file to manage dependencies, and it should be included in the same folder as the \u003ccode\u003eapp.yaml\u003c/code\u003e file for deployment dependency installation.\u003c/p\u003e\n"],["\u003cp\u003eTo avoid conflicts, source code should be kept separate from the app's directory where the \u003ccode\u003eapp.yaml\u003c/code\u003e file resides, with the \u003ccode\u003eGOPATH\u003c/code\u003e specifying an external directory for dependencies.\u003c/p\u003e\n"],["\u003cp\u003eTo deploy to app engine, all required libraries must be deployed along side the application code.\u003c/p\u003e\n"]]],[],null,["# Specify dependencies\n\nYou can use any linux/amd64-compatible package with instances running in the\nApp Engine flexible environment. These instructions assume you are using the `go get` command to\nget the packages directly from supported repositories, such as GitHub,\nBitbucket, LaunchPad, and others.\n\nStarting in Go version 1.22 and later:\n\n- You can't use `go get` outside of a module in the legacy `GOPATH`\n mode (`GO111MODULE`=`off`). For more information, see [Tools](https://tip.golang.org/doc/go1.22#:%7E:text=enables%20this%20feature.-,Tools,-Go%20command).\n\n- Go recommends that you use a `go.mod` file for managing dependencies. To install\n dependencies during deployment, include a `go.mod` file in the same folder as\n the `app.yaml` file. For more information about Go versions, and managing\n dependencies for vendor directories, see [GOPATH and Modules](https://pkg.go.dev/cmd/go#hdr-GOPATH_and_Modules).\n\nDeclare and manage dependencies\n-------------------------------\n\nGo applications are organized into packages that mirror the directory structure\nof your source files. When you use an import statement, the relative paths in\nthe import are interpreted. Valid import paths are fully-qualified\npaths that are relative to the `src` subdirectory of all the directories that\nare specified in your `GOPATH`.\n\nFor example, consider an example app where you define the following:\n\n- `GOPATH` module:\n\n export GOPATH=/home/fred/go.\n\n- `src1-1.go` file:\n\n import \"foo/bar\"\n\n- The gcloud CLI looks for the `foo/bar` package in the\n `/home/fred/go/src/foo/bar` location when you run or deploy the app.\n\nIf you include your package sources in `GOPATH`, you must be careful not to\nplace your source code within your app's directory where the `app.yaml`\nfile is located. If that happens, subtle problems can occur because a package\nmight get loaded twice, once for the path relative to a service's directory, and\nonce again for the fully-qualified path. To avoid problems, the gcloud CLI\nwill scan both your app's directory and `GOPATH`, and then report an error\nif a conflict is detected.\n\nFor best results, we recommend the following:\n\n- Create a separate directory in your app's directory for each service.\n- Each service's directory should contain the service's `app.yaml` file and one or more `.go` files.\n- Don't include any subdirectories in a service's directory.\n- Your `GOPATH` should specify a directory that is outside your app's directory and contain all the dependencies that your app imports.\n\nDownload required packages\n--------------------------\n\nYou can use the `go get` command to download packages. For example, to download\n`packagename` from the GitHub `my_repo`: \n\n go get github.com/my_repo/packagename\n\nDeploy to App Engine\n--------------------\n\nTo deploy your application to App Engine, you must deploy\nthe libraries that are required by your app along with your application code.\nFor complete details, see\n[Testing and deploying your application](/appengine/docs/flexible/testing-and-deploying-your-app#deploy)."]]