-
Notifications
You must be signed in to change notification settings - Fork 766
/
Copy pathversion.go
40 lines (33 loc) · 994 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package endpoints
import (
"encoding/json"
"net/http"
"github.com/golang/glog"
"github.com/prebid/prebid-server/v3/util/jsonutil"
)
const versionEndpointValueNotSet = "not-set"
// NewVersionEndpoint returns the latest git tag as the version and commit hash as the revision from which the binary was built
func NewVersionEndpoint(version, revision string) http.HandlerFunc {
response, err := prepareVersionEndpointResponse(version, revision)
if err != nil {
glog.Fatalf("error creating /version endpoint response: %v", err)
}
return func(w http.ResponseWriter, _ *http.Request) {
w.Write(response)
}
}
func prepareVersionEndpointResponse(version, revision string) (json.RawMessage, error) {
if version == "" {
version = versionEndpointValueNotSet
}
if revision == "" {
revision = versionEndpointValueNotSet
}
return jsonutil.Marshal(struct {
Revision string `json:"revision"`
Version string `json:"version"`
}{
Revision: revision,
Version: version,
})
}