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