You can use go:generate and go:embed to achieve this. In our CI/CD pipeline
we generate a json file with a lot of information like vcs, branch, tag,
date and time, hash and a lot more. Then we embed this json into the binary.

I became aware of this technique from
https://levelup.gitconnected.com/a-better-way-than-ldflags-to-add-a-build-version-to-your-go-binaries-2258ce419d2d?gi=c2bc81346d42
.

Hope this helps.

quin...@gmail.com <quint...@gmail.com> schrieb am Mo. 6. Feb. 2023 um 16:48:

>
> Hi,
>
> I would like to be able to extract the VCS branch name used during build.
> Currently I append "-X main.BranchName=${BRANCH}" to the build line which
> works, but I was hoping there might be a cunning way to extract this from
> runtime/debug?
>
> Thanks,
>
> -Steve
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/6f0a10e1-f818-4b98-8384-3fe925ec69dcn%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/6f0a10e1-f818-4b98-8384-3fe925ec69dcn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALWqRZqSMKbjEvOqF-AANNM4pFZ4cxEbmOKe46SRk7kU%3DdCwXQ%40mail.gmail.com.

Reply via email to