Skip to content

Commit f36b105

Browse files
committed
version: add user agent string
1 parent a6956a4 commit f36b105

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

version.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,37 @@ const (
2929
// appPreRelease MUST only contain characters from semanticAlphabet per
3030
// the semantic versioning spec.
3131
appPreRelease = "beta"
32+
33+
// defaultAgentName is the default name of the software that is added as
34+
// the first part of the user agent string.
35+
defaultAgentName = "loopd"
3236
)
3337

38+
// AgentName stores the name of the software that is added as the first part of
39+
// the user agent string. This defaults to the value "loopd" when being run as
40+
// a standalone component but can be overwritten by LiT for example when loopd
41+
// is integrated into the UI.
42+
var AgentName = defaultAgentName
43+
3444
// Version returns the application version as a properly formed string per the
35-
// semantic versioning 2.0.0 spec (http://semver.org/).
45+
// semantic versioning 2.0.0 spec (http://semver.org/) and the commit it was
46+
// built on.
3647
func Version() string {
48+
// Append commit hash of current build to version.
49+
return fmt.Sprintf("%s commit=%s", semanticVersion(), Commit)
50+
}
51+
52+
// UserAgent returns the full user agent string that identifies the software
53+
// that is submitting swaps to the loop server.
54+
func UserAgent() string {
55+
// Assemble full string, including the commit hash of current build.
56+
return fmt.Sprintf(
57+
"%s/v%s/commit=%s", AgentName, semanticVersion(), Commit,
58+
)
59+
}
60+
61+
// semanticVersion returns the SemVer part of the version.
62+
func semanticVersion() string {
3763
// Start with the major, minor, and patch versions.
3864
version := fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch)
3965

@@ -46,9 +72,6 @@ func Version() string {
4672
version = fmt.Sprintf("%s-%s", version, preRelease)
4773
}
4874

49-
// Append commit hash of current build to version.
50-
version = fmt.Sprintf("%s commit=%s", version, Commit)
51-
5275
return version
5376
}
5477

0 commit comments

Comments
 (0)