mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #2715 from xiang90/version
*: serve json version on both client and peer url
This commit is contained in:
commit
f077092bc1
@ -358,7 +358,7 @@ func serveVersion(w http.ResponseWriter, r *http.Request) {
|
||||
if !allowMethod(w, r.Method, "GET") {
|
||||
return
|
||||
}
|
||||
w.Write([]byte("etcd " + version.Version))
|
||||
w.Write(version.MarshalJSON())
|
||||
}
|
||||
|
||||
// parseKeyRequest converts a received http.Request on keysPrefix to
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@ -1327,9 +1326,9 @@ func TestServeVersion(t *testing.T) {
|
||||
if rw.Code != http.StatusOK {
|
||||
t.Errorf("code=%d, want %d", rw.Code, http.StatusOK)
|
||||
}
|
||||
w := fmt.Sprintf("etcd %s", version.Version)
|
||||
if g := rw.Body.String(); g != w {
|
||||
t.Fatalf("body = %q, want %q", g, w)
|
||||
w := version.MarshalJSON()
|
||||
if g := rw.Body.String(); g != string(w) {
|
||||
t.Fatalf("body = %q, want %q", g, string(w))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ func NewPeerHandler(clusterInfo etcdserver.ClusterInfo, timer etcdserver.RaftTim
|
||||
mux.Handle(rafthttp.RaftPrefix, raftHandler)
|
||||
mux.Handle(rafthttp.RaftPrefix+"/", raftHandler)
|
||||
mux.Handle(peerMembersPrefix, mh)
|
||||
mux.HandleFunc(versionPath, serveVersion)
|
||||
return mux
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
@ -37,6 +39,21 @@ const (
|
||||
DataDir2_0_1 DataDirVersion = "2.0.1"
|
||||
)
|
||||
|
||||
type Versions struct {
|
||||
Server string `json:"etcdserver"`
|
||||
// TODO: etcdcluster version
|
||||
// TODO: raft state machine version
|
||||
}
|
||||
|
||||
// MarshalJSON returns the JSON encoding of Versions struct.
|
||||
func MarshalJSON() []byte {
|
||||
b, err := json.Marshal(Versions{Server: Version})
|
||||
if err != nil {
|
||||
log.Panicf("version: cannot marshal versions to json (%v)", err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func DetectDataDir(dirpath string) (DataDirVersion, error) {
|
||||
names, err := fileutil.ReadDir(dirpath)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user