𝗣𝗮𝗰𝗸𝗮𝗴𝗲.𝗷𝘀𝗼𝗻 𝘃𝘀 𝗚𝗼.𝗺𝗼𝗱: 𝗪𝗵𝗲𝗿𝗲 𝗗𝗶𝗱 𝘁𝗵𝗲 𝗩𝗲𝗿𝘀𝗶𝗼𝗻 𝗙𝗶𝗲𝗹𝗱 𝗚𝗼?

If you move from JavaScript to Go, one thing will surprise you.

In a package.json file, the version is right at the top. You can read it. You can change it in a pull request. You can search for it. It is a fact that lives inside your code.

Now open a go.mod file. The version is not there.

This is not a mistake. It is a choice.

Go does not use a version field for your own module. Instead, Go uses git tags.

To set a version in Go, you do this:

The git tag is the single source of truth. When someone runs go get, Go looks at your repository tags to find the right commit.

This design has a major strength. A version can never point to the wrong code. In npm, the published code and the tagged source can drift apart. In Go, they are the same thing because the version is a pointer to a commit.

However, this changes your workflow in several ways:

Most other ecosystems keep the version in a file:

Go is different. It relies on git tags only.

If you want your Go binary to show a clean version, you can inject it during the build process using ldflags. Many developers also use tools like goreleaser to automate the tag and release process.

The two models represent different priorities:

Go chose the tag model to ensure the manifest always matches the code.

Per chi rilascia codice Go: che impressione ti dà il modello basato esclusivamente sui tag nel tuo lavoro quotidiano? Lo cambieresti?

Fonte: https://dev.to/dalirnet/packagejson-vs-gomod-where-did-the-version-field-go-3301