-
Notifications
You must be signed in to change notification settings - Fork 2
/
api_version.go
49 lines (45 loc) · 1.42 KB
/
api_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
package api
// Copyright 2016, JuanDeFu.ca. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
import (
"encoding/json"
"fmt"
"net/http"
"sabey.co/spoofgo/version"
)
type APIVersion struct {
Version string `json:"version"`
VersionState string `json:"version-state"`
Major int `json:"major"`
Minor int `json:"minor"`
Build int `json:"build"`
Versions []*version.Version `json:"versions,omitempty"`
Running bool `json:"running"`
Stopping bool `json:"stopping"`
Once bool `json:"once"`
}
func (self *Server) GetAPIVersion() *APIVersion {
return &APIVersion{
Version: self.version.GetUserAgent(),
VersionState: self.version.PrintVersionState(),
Major: self.version.GetMajor(),
Minor: self.version.GetMinor(),
Build: self.version.GetBuild(),
Versions: self.version.GetVersions(),
Running: self.version.IsRunning(),
Stopping: self.version.IsStop(),
Once: self.version.IsOnce(),
}
}
func (self *Server) APIVersionRespond(
api *APIVersion,
w http.ResponseWriter,
r *http.Request,
) {
self.Headers(w, CONTENT_JSON, 200)
if api == nil {
api = self.GetAPIVersion()
}
bs, _ := json.MarshalIndent(api, "", "\t")
fmt.Fprintf(w, "%s", bs)
}