Skip to content

Commit

Permalink
more doc/example for the library usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly committed Feb 12, 2023
1 parent ca7fdc3 commit 49e20fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 49e20fc

Please sign in to comment.