Xiang Li 12 éve
szülő
commit
5271da3d19
4 módosított fájl, 17 hozzáadás és 19 törlés
  1. 6 6
      client_handlers.go
  2. 8 9
      etcd.go
  3. 2 3
      raft_handlers.go
  4. 1 1
      version.go

+ 6 - 6
client_handlers.go

@@ -26,7 +26,7 @@ func Multiplexer(w http.ResponseWriter, req *http.Request) {
 }
 }
 
 
 //--------------------------------------
 //--------------------------------------
-// State sensitive handlers 
+// State sensitive handlers
 // Set/Delte will dispatch to leader
 // Set/Delte will dispatch to leader
 //--------------------------------------
 //--------------------------------------
 
 
@@ -76,7 +76,7 @@ func TestAndSetHttpHandler(w http.ResponseWriter, req *http.Request) {
 		warn("The given duration is not a number: %v", err)
 		warn("The given duration is not a number: %v", err)
 		w.WriteHeader(http.StatusInternalServerError)
 		w.WriteHeader(http.StatusInternalServerError)
 	}
 	}
-	
+
 	dispatch(command, &w, req)
 	dispatch(command, &w, req)
 
 
 }
 }
@@ -146,7 +146,7 @@ func dispatch(c Command, w *http.ResponseWriter, req *http.Request) {
 }
 }
 
 
 //--------------------------------------
 //--------------------------------------
-// State non-sensitive handlers 
+// State non-sensitive handlers
 // will not dispatch to leader
 // will not dispatch to leader
 // TODO: add sensitive version for these
 // TODO: add sensitive version for these
 // command?
 // command?
@@ -259,15 +259,15 @@ func WatchHttpHandler(w http.ResponseWriter, req *http.Request) {
 }
 }
 
 
 // Convert string duration to time format
 // Convert string duration to time format
-func durationToExpireTime(strDuration string) (time.Time, error){
+func durationToExpireTime(strDuration string) (time.Time, error) {
 	if strDuration != "" {
 	if strDuration != "" {
 		duration, err := strconv.Atoi(strDuration)
 		duration, err := strconv.Atoi(strDuration)
 
 
 		if err != nil {
 		if err != nil {
-			return time.Unix(0, 0),err
+			return time.Unix(0, 0), err
 		}
 		}
 		return time.Now().Add(time.Second * (time.Duration)(duration)), nil
 		return time.Now().Add(time.Second * (time.Duration)(duration)), nil
 	} else {
 	} else {
 		return time.Unix(0, 0), nil
 		return time.Unix(0, 0), nil
 	}
 	}
-}
+}

+ 8 - 9
etcd.go

@@ -147,7 +147,6 @@ func main() {
 		fatal("Please specify cert and key file or cert and key file and CAFile or none of the three")
 		fatal("Please specify cert and key file or cert and key file and CAFile or none of the three")
 	}
 	}
 
 
-
 	// Create transporter for raft
 	// Create transporter for raft
 	raftTransporter = createTransporter(st)
 	raftTransporter = createTransporter(st)
 
 
@@ -228,7 +227,7 @@ func main() {
 }
 }
 
 
 // Create transporter using by raft server
 // Create transporter using by raft server
-// Create http or https transporter based on 
+// Create http or https transporter based on
 // wether the user give the server cert and key
 // wether the user give the server cert and key
 func createTransporter(st int) transporter {
 func createTransporter(st int) transporter {
 	t := transporter{}
 	t := transporter{}
@@ -306,10 +305,10 @@ func startRaftTransport(port int, st int) {
 // Start to listen and response client command
 // Start to listen and response client command
 func startClientTransport(port int, st int) {
 func startClientTransport(port int, st int) {
 	// external commands
 	// external commands
-	http.HandleFunc("/" + version + "/keys/", Multiplexer)
-	http.HandleFunc("/" + version + "/watch/", WatchHttpHandler)
-	http.HandleFunc("/" + version + "/list/", ListHttpHandler)
-	http.HandleFunc("/" + version + "/testAndSet/", TestAndSetHttpHandler)
+	http.HandleFunc("/"+version+"/keys/", Multiplexer)
+	http.HandleFunc("/"+version+"/watch/", WatchHttpHandler)
+	http.HandleFunc("/"+version+"/list/", ListHttpHandler)
+	http.HandleFunc("/"+version+"/testAndSet/", TestAndSetHttpHandler)
 	http.HandleFunc("/leader", LeaderHttpHandler)
 	http.HandleFunc("/leader", LeaderHttpHandler)
 
 
 	switch st {
 	switch st {
@@ -363,7 +362,7 @@ func securityType(source int) int {
 	}
 	}
 
 
 	// If the user do not specify key file, cert file and
 	// If the user do not specify key file, cert file and
-	// CA file, the type will be HTTP  
+	// CA file, the type will be HTTP
 	if keyFile == "" && certFile == "" && CAFile == "" {
 	if keyFile == "" && certFile == "" && CAFile == "" {
 
 
 		return HTTP
 		return HTTP
@@ -372,12 +371,12 @@ func securityType(source int) int {
 
 
 	if keyFile != "" && certFile != "" {
 	if keyFile != "" && certFile != "" {
 		if CAFile != "" {
 		if CAFile != "" {
-			// If the user specify all the three file, the type 
+			// If the user specify all the three file, the type
 			// will be HTTPS with client cert auth
 			// will be HTTPS with client cert auth
 			return HTTPSANDVERIFY
 			return HTTPSANDVERIFY
 		}
 		}
 		// If the user specify key file and cert file but not
 		// If the user specify key file and cert file but not
-		// CA file, the type will be HTTPS without client cert 
+		// CA file, the type will be HTTPS without client cert
 		// auth
 		// auth
 		return HTTPS
 		return HTTPS
 	}
 	}

+ 2 - 3
raft_handlers.go

@@ -1,10 +1,10 @@
 package main
 package main
 
 
 import (
 import (
-	"net/http"
-	"strconv"
 	"encoding/json"
 	"encoding/json"
 	"github.com/coreos/go-raft"
 	"github.com/coreos/go-raft"
+	"net/http"
+	"strconv"
 )
 )
 
 
 //-------------------------------------------------------------
 //-------------------------------------------------------------
@@ -19,7 +19,6 @@ func GetLogHttpHandler(w http.ResponseWriter, req *http.Request) {
 	json.NewEncoder(w).Encode(raftServer.LogEntries())
 	json.NewEncoder(w).Encode(raftServer.LogEntries())
 }
 }
 
 
-
 // Response to vote request
 // Response to vote request
 func VoteHttpHandler(w http.ResponseWriter, req *http.Request) {
 func VoteHttpHandler(w http.ResponseWriter, req *http.Request) {
 	rvreq := &raft.RequestVoteRequest{}
 	rvreq := &raft.RequestVoteRequest{}

+ 1 - 1
version.go

@@ -1,3 +1,3 @@
 package main
 package main
 
 
-var version = "v1"
+var version = "v1"