During CI/CD we create a json file with a few details (git tag, branch, hash, date, time). Afterwards we compile Go Code which embeds this file into the binary. During runtime flags like --version print the json.
Note that this is about the version of some binary - not the version of a package. However, you could embed go.mod. But there may be better ways. Hope this helps. 'Mark' via golang-nuts <golang-nuts@googlegroups.com> schrieb am Di. 1. Nov. 2022 um 16:34: > I am creating a pkg. > It has a `go.mod` file: > ``` > module github.com/.../mypkg > > go 1.19 > ``` > And code files with functions in .go files all in the mypkg pkg. > > How do I specify which version the mypkg pkg is? I know about using `$ > git tag vX.Y.Z` and `$ git push origin vX.Y.Z`, but is there any way I can > have this version in a file that can be accessed at build time or runtime? > > -- > 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/0a16b738-59e5-4885-90c8-cd168e308623n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/0a16b738-59e5-4885-90c8-cd168e308623n%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/CALWqRZov4r%2BN2FiZug5mmwUwhYcvf08922UQU%3DMqfJKLFT8dBg%40mail.gmail.com.