mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-08 20:07:51 +00:00
Makes /version endpoint semver-compatible
This commit is contained in:
parent
311f9699b7
commit
bc49d1e6fd
2 changed files with 11 additions and 2 deletions
|
|
@ -1590,10 +1590,15 @@ func (h *Handler) handleGetHosts(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// handleGetVersion handles /version requests.
|
||||
func (h *Handler) handleGetVersion(w http.ResponseWriter, r *http.Request) {
|
||||
version := Version
|
||||
if strings.HasPrefix(version, "v") {
|
||||
// make the version string semver-compatible
|
||||
version = version[1:]
|
||||
}
|
||||
if err := json.NewEncoder(w).Encode(struct {
|
||||
Version string `json:"version"`
|
||||
}{
|
||||
Version: Version,
|
||||
Version: version,
|
||||
}); err != nil {
|
||||
h.logger().Printf("write version response error: %s", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1161,9 +1161,13 @@ func TestHandler_Version(t *testing.T) {
|
|||
w := httptest.NewRecorder()
|
||||
r := test.MustNewHTTPRequest("GET", "/version", nil)
|
||||
h.ServeHTTP(w, r)
|
||||
version := pilosa.Version
|
||||
if strings.HasPrefix(version, "v") {
|
||||
version = version[1:]
|
||||
}
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("unexpected status code: %d", w.Code)
|
||||
} else if w.Body.String() != `{"version":"`+pilosa.Version+`"}`+"\n" {
|
||||
} else if w.Body.String() != `{"version":"`+version+`"}`+"\n" {
|
||||
t.Fatalf("unexpected body: %q", w.Body.String())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue