util/useragent: use more verbose version

This commit is contained in:
Euan Kemp 2018-04-04 16:18:37 -07:00
parent 4e5a2d1646
commit 6b4e33a483
2 changed files with 17 additions and 4 deletions

View File

@ -4,19 +4,19 @@ import (
"net/http"
)
// CertManagerUserAgent is the user agent that http clients in this codebase should use
var CertManagerUserAgent = "jetstack-cert-manager/" + version()
// UserAgentRoundTripper implements the http.RoundTripper interface and adds a User-Agent
// header.
type userAgentRoundTripper struct {
inner http.RoundTripper
}
// CertManagerUserAgent is the user agent that http clients in this codebase should use
const CertManagerUserAgent = "jetstack-cert-manager/" + AppVersion
// UserAgentRoundTripper returns a RoundTripper that functions identically to
// the provided 'inner' round tripper, other than also setting a user agent.
func UserAgentRoundTripper(inner http.RoundTripper) http.RoundTripper {
return UserAgentRoundTripper{
return userAgentRoundTripper{
inner: inner,
}
}

View File

@ -1,7 +1,20 @@
package util
import "fmt"
var (
AppGitState = ""
AppGitCommit = ""
AppVersion = "canary"
)
func version() string {
v := AppVersion
if AppGitCommit != "" {
v += "-" + AppGitCommit
}
if AppGitState != "" {
v += fmt.Sprintf(" (%v)", AppGitState)
}
return v
}