diff --git a/README.md b/README.md index 3cdd0d9..44b6baf 100644 --- a/README.md +++ b/README.md @@ -35,3 +35,14 @@ build GOOS=darwin $ ~/go/bin/sample 2023/02/12 13:34:37 fortio.org/version sample main started 1.0.0 h1:JbGoGiNQ0883KoVPDsYhQCQ32QkAVTtECn86XVRRYi4= go1.19.5 arm64 darwin ``` + +Libraries can embed their own version using for instance +```golang +func init() { //nolint:gochecknoinits // we do need an init for this + shortVersion, longVersion, fullVersion = version.FromBuildInfoPath("fortio.org/fortio") +} +``` + +and the `longVersion` in this example can then show both the module/library version and the version of the containing binary. eg + +fortio 1.40.0 h1:jSDO/jGcyC/qTpMZZ84EZbn9BQawsWM9/RMQ9s6Cn3w= go1.19.5 arm64 darwin (in fortio.org/fortiotel 1.3.0) diff --git a/version.go b/version.go index a771181..0a988db 100644 --- a/version.go +++ b/version.go @@ -62,6 +62,8 @@ func getVersion(binfo *debug.BuildInfo, path string) (short, sum, mainPath, base // FromBuildInfoPath returns the version of as specific module if that module isn't already the main one. // Used by Fortio library version init to remember it's own version. +// Can be used by any other library to extract their own running version. +// It will also indicate the containing binary's version if the module is not the main one. func FromBuildInfoPath(path string) (short, long, full string) { binfo, ok := debug.ReadBuildInfo() if !ok {