Resolve semantic and pseudo versions
Resolve semantic and pseudo versions
Go module versions use semantic versioning: vMAJOR.MINOR.PATCH, optionally with a prerelease suffix. A breaking major version v2 or higher normally needs a matching /v2 or higher module-path suffix. A pseudo-version encodes a revision timestamp and short commit hash, with a base that preserves ordering relative to tagged releases. Let go get derive pseudo-versions from revisions; do not invent them for real repositories.
Use a fresh directory for each example, create the listed files (labels are not file contents), and run the commands in a POSIX shell. Use Go 1.23+, local toolchain, and Python 3 only for the synthetic proxy examples. For isolation, set GOWORK=off, GOTOOLCHAIN=local, GOPROXY=off and GOSUMDB=off for these local labs only; use a fresh GOMODCACHE per lab. Proxy examples override GOPROXY to a local file URL. Do not copy disabled checksum settings to real projects.
--- proxy.py ---from pathlib import Pathimport json, zipfileroot=Path("proxy")for version in ("v1.0.0", "v1.1.0", "v1.2.0", "v1.3.0", "v1.2.1-0.20240102030405-abcdef123456"): path="example.test/lib" d=root/path/"@v"; d.mkdir(parents=True,exist_ok=True) mod="module "+path+"\n\ngo 1.23.0\n" if version=="v1.3.0": mod+="\nretract v1.2.0 // demonstration\n" (d/(version+".mod")).write_text(mod) (d/(version+".info")).write_text(json.dumps({"Version":version,"Time":"2024-01-02T03:04:05Z"})) with zipfile.ZipFile(d/(version+".zip"),"w") as z: prefix=path+"@"+version+"/" z.writestr(prefix+"go.mod",mod) z.writestr(prefix+"lib.go",'package lib\nfunc Version() string { return "'+version+'" }\n') (d/"list").write_text("v1.0.0\nv1.1.0\nv1.2.0\nv1.3.0\n")
--- go.mod ---module example.test/app
go 1.23.0
--- main.go ---package main
import ( "example.test/lib" "fmt")
func main() { fmt.Println(lib.Version()) }
--- Commands (shell, from project root) ---python3 proxy.pyexport GOPROXY="file://$PWD/proxy" GOSUMDB=off GONOSUMDB=none GOPRIVATE= GONOPROXY=nonego get example.test/lib@v1.1.0 2>/dev/nullgo list -m example.test/libgo run .An explicit version query adds the requirement and downloads the named version. The synthetic dependency reports its version for teaching. Review go.mod and go.sum after go get; real upgrades may change other requirements.
Expected output:
example.test/lib v1.1.0v1.1.0Inspect a synthetic pseudo-version
--- proxy.py ---from pathlib import Pathimport json, zipfileroot=Path("proxy")for version in ("v1.0.0", "v1.1.0", "v1.2.0", "v1.3.0", "v1.2.1-0.20240102030405-abcdef123456"): path="example.test/lib" d=root/path/"@v"; d.mkdir(parents=True,exist_ok=True) mod="module "+path+"\n\ngo 1.23.0\n" if version=="v1.3.0": mod+="\nretract v1.2.0 // demonstration\n" (d/(version+".mod")).write_text(mod) (d/(version+".info")).write_text(json.dumps({"Version":version,"Time":"2024-01-02T03:04:05Z"})) with zipfile.ZipFile(d/(version+".zip"),"w") as z: prefix=path+"@"+version+"/" z.writestr(prefix+"go.mod",mod) z.writestr(prefix+"lib.go",'package lib\nfunc Version() string { return "'+version+'" }\n') (d/"list").write_text("v1.0.0\nv1.1.0\nv1.2.0\nv1.3.0\n")
--- go.mod ---module example.test/app
go 1.23.0
--- main.go ---package main
import ( "example.test/lib" "fmt")
func main() { fmt.Println(lib.Version()) }
--- Commands (shell, from project root) ---python3 proxy.pyexport GOPROXY="file://$PWD/proxy" GOSUMDB=off GONOSUMDB=none GOPRIVATE= GONOPROXY=nonego get example.test/lib@v1.2.1-0.20240102030405-abcdef123456 2>/dev/nullgo list -m example.test/libgo run .This fixture supplies a deliberately fictional pseudo-version through a local proxy, not a real Git revision. Its format sorts after v1.2.0 and before v1.2.1. Real pseudo-versions are validated against revision history by the Go tooling when fetched from version control.
Expected output:
example.test/lib v1.2.1-0.20240102030405-abcdef123456v1.2.1-0.20240102030405-abcdef123456Try it locally
Choose synthetic v1.0.0 with go get and print its selected version.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Modules and workspaces 03: Resolve semantic and pseudo versions
Check the lesson objective before moving on.
What suffix normally belongs to a v2 module path?
Should you manually invent a pseudo-version for a real commit?