mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
change name to url in http handlers
This commit is contained in:
parent
8e48a20c85
commit
32d1681b6b
@ -5,7 +5,6 @@ import (
|
||||
"github.com/coreos/etcd/store"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
@ -45,7 +44,7 @@ func SetHttpHandler(w *http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
debugf("[recv] POST %v/v1/keys/%s", raftServer.Name(), key)
|
||||
debugf("[recv] POST %v/v1/keys/%s", info.EtcdURL, key)
|
||||
|
||||
value := req.FormValue("value")
|
||||
|
||||
@ -96,7 +95,7 @@ func SetHttpHandler(w *http.ResponseWriter, req *http.Request) {
|
||||
func DeleteHttpHandler(w *http.ResponseWriter, req *http.Request) {
|
||||
key := req.URL.Path[len("/v1/keys/"):]
|
||||
|
||||
debugf("[recv] DELETE %v/v1/keys/%s", raftServer.Name(), key)
|
||||
debugf("[recv] DELETE %v/v1/keys/%s", info.EtcdURL, key)
|
||||
|
||||
command := &DeleteCommand{
|
||||
Key: key,
|
||||
@ -251,7 +250,7 @@ func StatsHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||
func GetHttpHandler(w *http.ResponseWriter, req *http.Request) {
|
||||
key := req.URL.Path[len("/v1/keys/"):]
|
||||
|
||||
debugf("[recv] GET http://%v/v1/keys/%s", raftServer.Name(), key)
|
||||
debugf("[recv] GET %s/v1/keys/%s", info.EtcdURL, key)
|
||||
|
||||
command := &GetCommand{
|
||||
Key: key,
|
||||
@ -290,13 +289,13 @@ func WatchHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
if req.Method == "GET" {
|
||||
debugf("[recv] GET http://%v/watch/%s", raftServer.Name(), key)
|
||||
debugf("[recv] GET %s/watch/%s", info.EtcdURL, key)
|
||||
command.SinceIndex = 0
|
||||
|
||||
} else if req.Method == "POST" {
|
||||
// watch from a specific index
|
||||
|
||||
debugf("[recv] POST http://%v/watch/%s", raftServer.Name(), key)
|
||||
debugf("[recv] POST %s/watch/%s", info.EtcdURL, key)
|
||||
content := req.FormValue("index")
|
||||
|
||||
sinceIndex, err := strconv.ParseUint(string(content), 10, 64)
|
||||
@ -340,17 +339,3 @@ func TestHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// Convert string duration to time format
|
||||
func durationToExpireTime(strDuration string) (time.Time, error) {
|
||||
if strDuration != "" {
|
||||
duration, err := strconv.Atoi(strDuration)
|
||||
|
||||
if err != nil {
|
||||
return time.Unix(0, 0), err
|
||||
}
|
||||
return time.Now().Add(time.Second * (time.Duration)(duration)), nil
|
||||
} else {
|
||||
return time.Unix(0, 0), nil
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,7 @@ import (
|
||||
|
||||
// Get all the current logs
|
||||
func GetLogHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||
u, _ := nameToRaftURL(raftServer.Name())
|
||||
debugf("[recv] GET %s/log", u)
|
||||
debugf("[recv] GET %s/log", info.RaftURL)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(raftServer.LogEntries())
|
||||
@ -24,8 +23,7 @@ func VoteHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||
rvreq := &raft.RequestVoteRequest{}
|
||||
err := decodeJsonRequest(req, rvreq)
|
||||
if err == nil {
|
||||
u, _ := nameToRaftURL(raftServer.Name())
|
||||
debugf("[recv] POST %s/vote [%s]", u, rvreq.CandidateName)
|
||||
debugf("[recv] POST %s/vote [%s]", info.RaftURL, rvreq.CandidateName)
|
||||
if resp := raftServer.RequestVote(rvreq); resp != nil {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(resp)
|
||||
@ -42,8 +40,7 @@ func AppendEntriesHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||
err := decodeJsonRequest(req, aereq)
|
||||
|
||||
if err == nil {
|
||||
u, _ := nameToRaftURL(raftServer.Name())
|
||||
debugf("[recv] POST %s/log/append [%d]", u, len(aereq.Entries))
|
||||
debugf("[recv] POST %s/log/append [%d]", info.RaftURL, len(aereq.Entries))
|
||||
if resp := raftServer.AppendEntries(aereq); resp != nil {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(resp)
|
||||
@ -62,8 +59,7 @@ func SnapshotHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||
aereq := &raft.SnapshotRequest{}
|
||||
err := decodeJsonRequest(req, aereq)
|
||||
if err == nil {
|
||||
u, _ := nameToRaftURL(raftServer.Name())
|
||||
debugf("[recv] POST %s/snapshot/ ", u)
|
||||
debugf("[recv] POST %s/snapshot/ ", info.RaftURL)
|
||||
if resp := raftServer.RequestSnapshot(aereq); resp != nil {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(resp)
|
||||
@ -79,8 +75,7 @@ func SnapshotRecoveryHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||
aereq := &raft.SnapshotRecoveryRequest{}
|
||||
err := decodeJsonRequest(req, aereq)
|
||||
if err == nil {
|
||||
u, _ := nameToRaftURL(raftServer.Name())
|
||||
debugf("[recv] POST %s/snapshotRecovery/ ", u)
|
||||
debugf("[recv] POST %s/snapshotRecovery/ ", info.RaftURL)
|
||||
if resp := raftServer.SnapshotRecoveryRequest(aereq); resp != nil {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(resp)
|
||||
@ -93,8 +88,7 @@ func SnapshotRecoveryHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
// Get the port that listening for etcd connecting of the server
|
||||
func EtcdURLHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||
u, _ := nameToRaftURL(raftServer.Name())
|
||||
debugf("[recv] Get %s/etcdURL/ ", u)
|
||||
debugf("[recv] Get %s/etcdURL/ ", info.RaftURL)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(argInfo.EtcdURL))
|
||||
}
|
||||
@ -115,9 +109,7 @@ func JoinHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
// Response to the name request
|
||||
func NameHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||
u, _ := nameToRaftURL(raftServer.Name())
|
||||
|
||||
debugf("[recv] Get %s/name/ ", u)
|
||||
debugf("[recv] Get %s/name/ ", info.RaftURL)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(raftServer.Name()))
|
||||
}
|
||||
|
20
util.go
20
util.go
@ -8,8 +8,28 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
//--------------------------------------
|
||||
// etcd http Helper
|
||||
//--------------------------------------
|
||||
|
||||
// Convert string duration to time format
|
||||
func durationToExpireTime(strDuration string) (time.Time, error) {
|
||||
if strDuration != "" {
|
||||
duration, err := strconv.Atoi(strDuration)
|
||||
|
||||
if err != nil {
|
||||
return time.Unix(0, 0), err
|
||||
}
|
||||
return time.Now().Add(time.Second * (time.Duration)(duration)), nil
|
||||
} else {
|
||||
return time.Unix(0, 0), nil
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Web Helper
|
||||
//--------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user