/
version.go
53 lines (46 loc) · 1.56 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
package rest
import (
"net/http"
restfulspec "github.com/emicklei/go-restful-openapi/v2"
restful "github.com/emicklei/go-restful/v3"
"github.com/metal-stack/metal-lib/httperrors"
"github.com/metal-stack/v"
)
// name this struct "version", so go-swagger will generate a type named "version"
type version struct {
Name string `json:"name"`
Version string `json:"version"`
BuildDate string `json:"builddate"`
Revision string `json:"revision"`
Gitsha1 string `json:"gitsha1"`
MinimumClientVersion string `json:"min_client_version"`
}
// NewVersion returns a webservice which returns version information. The given
// name should be a descriptive name of the module.
func NewVersion(name string, basePath string, minClientVersion string) *restful.WebService {
ws := new(restful.WebService)
ws.
Path(basePath + "v1/version").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
tags := []string{"version"}
vi := version{
Name: name,
Version: v.Version,
Revision: v.Revision,
BuildDate: v.BuildDate,
Gitsha1: v.GitSHA1,
MinimumClientVersion: minClientVersion,
}
ws.Route(
ws.GET("/").
Doc("returns the current version information of this module").
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(http.StatusOK, "OK", version{}).
Operation("info").
To(func(r *restful.Request, rsp *restful.Response) {
_ = rsp.WriteAsJson(vi)
}).
DefaultReturns("Error", httperrors.HTTPErrorResponse{}))
return ws
}