-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add go-libipni user-agent header with version to HTTTP announce (#60)
- Loading branch information
Showing
4 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package libipni | ||
|
||
import ( | ||
_ "embed" | ||
"encoding/json" | ||
"runtime/debug" | ||
) | ||
|
||
var ( | ||
// Release is the release version tag value, e.g. "v1.2.3" | ||
Release string | ||
// Revision is the git commit hash. | ||
Revision string | ||
// Version is the full version string: Release-Revision. | ||
Version string | ||
) | ||
|
||
//go:embed version.json | ||
var versionJSON []byte | ||
|
||
func init() { | ||
// Read version from embedded JSON file. | ||
var verMap map[string]string | ||
json.Unmarshal(versionJSON, &verMap) | ||
Release = verMap["version"] | ||
|
||
// If running from a module, try to get the build info. | ||
bi, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return | ||
} | ||
|
||
// Append the revision to the version. | ||
for i := range bi.Settings { | ||
if bi.Settings[i].Key == "vcs.revision" { | ||
Revision = bi.Settings[i].Value | ||
Version = Release + "-" + Revision | ||
break | ||
} | ||
} | ||
} |