golang 에서 커밋 해시를 바이너리에 넣는 방법을 찾아보는 중
아래 방법은 링커에서 변수에 넣는것 같은데 이것도 쓸만해 보이긴 한데..
| go build -ldflags "-X my/package/config.Version=1.0.0" |
go version은 좀더 상세한 자료가 들어가는것 같은데 좀더 나은 접근 방법이 될 듯?
| go version The go command now embeds version control information in binaries. It includes the currently checked-out revision, commit time, and a flag indicating whether edited or untracked files are present. Version control information is embedded if the go command is invoked in a directory within a Git, Mercurial, Fossil, or Bazaar repository, and the main package and its containing main module are in the same repository. This information may be omitted using the flag -buildvcs=false. Additionally, the go command embeds information about the build, including build and tool tags (set with -tags), compiler, assembler, and linker flags (like -gcflags), whether cgo was enabled, and if it was, the values of the cgo environment variables (like CGO_CFLAGS). Both VCS and build information may be read together with module information using go version -m file or runtime/debug.ReadBuildInfo (for the currently running binary) or the new debug/buildinfo package. The underlying data format of the embedded build information can change with new go releases, so an older version of go may not handle the build information produced with a newer version of go. To read the version information from a binary built with go 1.18, use the go version command and the debug/buildinfo package from go 1.18+. |
'Programming > golang' 카테고리의 다른 글
| golang 정적웹 파일 포함하기 (0) | 2025.11.24 |
|---|---|
| go vet (golang 정적분석) (0) | 2025.10.02 |
| golang 윈도우 서비스 프로그램 작성하기 (0) | 2025.02.18 |
| golang tcp socket timeout 주기(listen, read) (0) | 2024.04.08 |
| golang reflect (0) | 2024.02.20 |
