Browse Source

add error package

Xiang Li 12 years ago
parent
commit
cf2d6888c2

+ 3 - 1
command.go

@@ -3,6 +3,7 @@ package main
 import (
 import (
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
+	etcdErr "github.com/coreos/etcd/error"
 	"github.com/coreos/etcd/store"
 	"github.com/coreos/etcd/store"
 	"github.com/coreos/go-raft"
 	"github.com/coreos/go-raft"
 	"path"
 	"path"
@@ -147,7 +148,8 @@ func (c *JoinCommand) Apply(raftServer *raft.Server) (interface{}, error) {
 	// check machine number in the cluster
 	// check machine number in the cluster
 	num := machineNum()
 	num := machineNum()
 	if num == maxClusterSize {
 	if num == maxClusterSize {
-		return []byte("join fail"), fmt.Errorf(errors[103])
+		debug("Reject join request from ", c.Name)
+		return []byte("join fail"), etcdErr.NewError(103, "")
 	}
 	}
 
 
 	addNameToURL(c.Name, c.RaftURL, c.EtcdURL)
 	addNameToURL(c.Name, c.RaftURL, c.EtcdURL)

+ 27 - 6
error.go → error/error.go

@@ -1,11 +1,14 @@
-package main
+package error
 
 
 import (
 import (
 	"encoding/json"
 	"encoding/json"
+	"net/http"
 )
 )
 
 
 var errors map[int]string
 var errors map[int]string
 
 
+const ()
+
 func init() {
 func init() {
 	errors = make(map[int]string)
 	errors = make(map[int]string)
 
 
@@ -33,21 +36,39 @@ func init() {
 
 
 }
 }
 
 
-type etcdError struct {
+type Error struct {
 	ErrorCode int    `json:"errorCode"`
 	ErrorCode int    `json:"errorCode"`
 	Message   string `json:"message"`
 	Message   string `json:"message"`
 	Cause     string `json:"cause,omitempty"`
 	Cause     string `json:"cause,omitempty"`
 }
 }
 
 
-func newEtcdError(errorCode int, cause string) *etcdError {
-	return &etcdError{
+func NewError(errorCode int, cause string) Error {
+	return Error{
 		ErrorCode: errorCode,
 		ErrorCode: errorCode,
 		Message:   errors[errorCode],
 		Message:   errors[errorCode],
 		Cause:     cause,
 		Cause:     cause,
 	}
 	}
 }
 }
 
 
-func (e *etcdError) toJson() []byte {
+func Message(code int) string {
+	return errors[code]
+}
+
+// Only for error interface
+func (e Error) Error() string {
+	return e.Message
+}
+
+func (e Error) toJsonString() string {
 	b, _ := json.Marshal(e)
 	b, _ := json.Marshal(e)
-	return b
+	return string(b)
+}
+
+func (e Error) Write(w http.ResponseWriter) {
+	// 3xx is reft internal error
+	if e.ErrorCode/100 == 3 {
+		http.Error(w, e.toJsonString(), http.StatusInternalServerError)
+	} else {
+		http.Error(w, e.toJsonString(), http.StatusBadRequest)
+	}
 }
 }

+ 35 - 61
etcd_handlers.go

@@ -2,6 +2,7 @@ package main
 
 
 import (
 import (
 	"fmt"
 	"fmt"
+	etcdErr "github.com/coreos/etcd/error"
 	"github.com/coreos/etcd/store"
 	"github.com/coreos/etcd/store"
 	"github.com/coreos/go-raft"
 	"github.com/coreos/go-raft"
 	"net/http"
 	"net/http"
@@ -16,31 +17,32 @@ import (
 func NewEtcdMuxer() *http.ServeMux {
 func NewEtcdMuxer() *http.ServeMux {
 	// external commands
 	// external commands
 	etcdMux := http.NewServeMux()
 	etcdMux := http.NewServeMux()
-	etcdMux.Handle("/"+version+"/keys/", etcdHandler(Multiplexer))
-	etcdMux.Handle("/"+version+"/watch/", etcdHandler(WatchHttpHandler))
-	etcdMux.Handle("/leader", etcdHandler(LeaderHttpHandler))
-	etcdMux.Handle("/machines", etcdHandler(MachinesHttpHandler))
-	etcdMux.Handle("/version", etcdHandler(VersionHttpHandler))
-	etcdMux.Handle("/stats", etcdHandler(StatsHttpHandler))
+	etcdMux.Handle("/"+version+"/keys/", errorHandler(Multiplexer))
+	etcdMux.Handle("/"+version+"/watch/", errorHandler(WatchHttpHandler))
+	etcdMux.Handle("/"+version+"/leader", errorHandler(LeaderHttpHandler))
+	etcdMux.Handle("/"+version+"/machines", errorHandler(MachinesHttpHandler))
+	etcdMux.Handle("/"+version+"/stats", errorHandler(StatsHttpHandler))
+	etcdMux.Handle("/version", errorHandler(VersionHttpHandler))
 	etcdMux.HandleFunc("/test/", TestHttpHandler)
 	etcdMux.HandleFunc("/test/", TestHttpHandler)
 	return etcdMux
 	return etcdMux
 }
 }
 
 
-type etcdHandler func(http.ResponseWriter, *http.Request) *etcdError
+type errorHandler func(http.ResponseWriter, *http.Request) error
 
 
-func (fn etcdHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+func (fn errorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	if e := fn(w, r); e != nil {
 	if e := fn(w, r); e != nil {
-		// 3xx is reft internal error
-		if e.ErrorCode/100 == 3 {
-			http.Error(w, string(e.toJson()), http.StatusInternalServerError)
+		fmt.Println(e)
+		if etcdErr, ok := e.(etcdErr.Error); ok {
+			debug("Return error: ", etcdErr.Error())
+			etcdErr.Write(w)
 		} else {
 		} else {
-			http.Error(w, string(e.toJson()), http.StatusBadRequest)
+			http.Error(w, e.Error(), http.StatusInternalServerError)
 		}
 		}
 	}
 	}
 }
 }
 
 
 // Multiplex GET/POST/DELETE request to corresponding handlers
 // Multiplex GET/POST/DELETE request to corresponding handlers
-func Multiplexer(w http.ResponseWriter, req *http.Request) *etcdError {
+func Multiplexer(w http.ResponseWriter, req *http.Request) error {
 
 
 	switch req.Method {
 	switch req.Method {
 	case "GET":
 	case "GET":
@@ -61,11 +63,11 @@ func Multiplexer(w http.ResponseWriter, req *http.Request) *etcdError {
 //--------------------------------------
 //--------------------------------------
 
 
 // Set Command Handler
 // Set Command Handler
-func SetHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
+func SetHttpHandler(w http.ResponseWriter, req *http.Request) error {
 	key := req.URL.Path[len("/v1/keys/"):]
 	key := req.URL.Path[len("/v1/keys/"):]
 
 
 	if store.CheckKeyword(key) {
 	if store.CheckKeyword(key) {
-		return newEtcdError(400, "Set")
+		return etcdErr.NewError(400, "Set")
 	}
 	}
 
 
 	debugf("[recv] POST %v/v1/keys/%s [%s]", e.url, key, req.RemoteAddr)
 	debugf("[recv] POST %v/v1/keys/%s [%s]", e.url, key, req.RemoteAddr)
@@ -73,7 +75,7 @@ func SetHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
 	value := req.FormValue("value")
 	value := req.FormValue("value")
 
 
 	if len(value) == 0 {
 	if len(value) == 0 {
-		return newEtcdError(200, "Set")
+		return etcdErr.NewError(200, "Set")
 	}
 	}
 
 
 	prevValue := req.FormValue("prevValue")
 	prevValue := req.FormValue("prevValue")
@@ -83,7 +85,7 @@ func SetHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
 	expireTime, err := durationToExpireTime(strDuration)
 	expireTime, err := durationToExpireTime(strDuration)
 
 
 	if err != nil {
 	if err != nil {
-		return newEtcdError(202, "Set")
+		return etcdErr.NewError(202, "Set")
 	}
 	}
 
 
 	if len(prevValue) != 0 {
 	if len(prevValue) != 0 {
@@ -108,7 +110,7 @@ func SetHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
 }
 }
 
 
 // Delete Handler
 // Delete Handler
-func DeleteHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
+func DeleteHttpHandler(w http.ResponseWriter, req *http.Request) error {
 	key := req.URL.Path[len("/v1/keys/"):]
 	key := req.URL.Path[len("/v1/keys/"):]
 
 
 	debugf("[recv] DELETE %v/v1/keys/%s [%s]", e.url, key, req.RemoteAddr)
 	debugf("[recv] DELETE %v/v1/keys/%s [%s]", e.url, key, req.RemoteAddr)
@@ -121,35 +123,14 @@ func DeleteHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
 }
 }
 
 
 // Dispatch the command to leader
 // Dispatch the command to leader
-func dispatch(c Command, w http.ResponseWriter, req *http.Request, etcd bool) *etcdError {
+func dispatch(c Command, w http.ResponseWriter, req *http.Request, etcd bool) error {
 
 
 	if r.State() == raft.Leader {
 	if r.State() == raft.Leader {
 		if body, err := r.Do(c); err != nil {
 		if body, err := r.Do(c); err != nil {
-
-			// store error
-			if _, ok := err.(store.NotFoundError); ok {
-				return newEtcdError(100, err.Error())
-			}
-
-			if _, ok := err.(store.TestFail); ok {
-				return newEtcdError(101, err.Error())
-			}
-
-			if _, ok := err.(store.NotFile); ok {
-				return newEtcdError(102, err.Error())
-			}
-
-			// join error
-			if err.Error() == errors[103] {
-				return newEtcdError(103, "")
-			}
-
-			// raft internal error
-			return newEtcdError(300, err.Error())
-
+			return err
 		} else {
 		} else {
 			if body == nil {
 			if body == nil {
-				return newEtcdError(300, "Empty result from raft")
+				return etcdErr.NewError(300, "Empty result from raft")
 			} else {
 			} else {
 				body, _ := body.([]byte)
 				body, _ := body.([]byte)
 				w.WriteHeader(http.StatusOK)
 				w.WriteHeader(http.StatusOK)
@@ -162,7 +143,7 @@ func dispatch(c Command, w http.ResponseWriter, req *http.Request, etcd bool) *e
 		leader := r.Leader()
 		leader := r.Leader()
 		// current no leader
 		// current no leader
 		if leader == "" {
 		if leader == "" {
-			return newEtcdError(300, "")
+			return etcdErr.NewError(300, "")
 		}
 		}
 
 
 		// tell the client where is the leader
 		// tell the client where is the leader
@@ -183,7 +164,7 @@ func dispatch(c Command, w http.ResponseWriter, req *http.Request, etcd bool) *e
 		http.Redirect(w, req, url, http.StatusTemporaryRedirect)
 		http.Redirect(w, req, url, http.StatusTemporaryRedirect)
 		return nil
 		return nil
 	}
 	}
-	return newEtcdError(300, "")
+	return etcdErr.NewError(300, "")
 }
 }
 
 
 //--------------------------------------
 //--------------------------------------
@@ -194,7 +175,7 @@ func dispatch(c Command, w http.ResponseWriter, req *http.Request, etcd bool) *e
 //--------------------------------------
 //--------------------------------------
 
 
 // Handler to return the current leader's raft address
 // Handler to return the current leader's raft address
-func LeaderHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
+func LeaderHttpHandler(w http.ResponseWriter, req *http.Request) error {
 	leader := r.Leader()
 	leader := r.Leader()
 
 
 	if leader != "" {
 	if leader != "" {
@@ -203,12 +184,12 @@ func LeaderHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
 		w.Write([]byte(raftURL))
 		w.Write([]byte(raftURL))
 		return nil
 		return nil
 	} else {
 	} else {
-		return newEtcdError(301, "")
+		return etcdErr.NewError(301, "")
 	}
 	}
 }
 }
 
 
 // Handler to return all the known machines in the current cluster
 // Handler to return all the known machines in the current cluster
-func MachinesHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
+func MachinesHttpHandler(w http.ResponseWriter, req *http.Request) error {
 	machines := getMachines()
 	machines := getMachines()
 
 
 	w.WriteHeader(http.StatusOK)
 	w.WriteHeader(http.StatusOK)
@@ -217,22 +198,21 @@ func MachinesHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
 }
 }
 
 
 // Handler to return the current version of etcd
 // Handler to return the current version of etcd
-func VersionHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
+func VersionHttpHandler(w http.ResponseWriter, req *http.Request) error {
 	w.WriteHeader(http.StatusOK)
 	w.WriteHeader(http.StatusOK)
 	fmt.Fprintf(w, "etcd %s", releaseVersion)
 	fmt.Fprintf(w, "etcd %s", releaseVersion)
-	fmt.Fprintf(w, "etcd API %s", version)
 	return nil
 	return nil
 }
 }
 
 
 // Handler to return the basic stats of etcd
 // Handler to return the basic stats of etcd
-func StatsHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
+func StatsHttpHandler(w http.ResponseWriter, req *http.Request) error {
 	w.WriteHeader(http.StatusOK)
 	w.WriteHeader(http.StatusOK)
 	w.Write(etcdStore.Stats())
 	w.Write(etcdStore.Stats())
 	return nil
 	return nil
 }
 }
 
 
 // Get Handler
 // Get Handler
-func GetHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
+func GetHttpHandler(w http.ResponseWriter, req *http.Request) error {
 	key := req.URL.Path[len("/v1/keys/"):]
 	key := req.URL.Path[len("/v1/keys/"):]
 
 
 	debugf("[recv] GET %s/v1/keys/%s [%s]", e.url, key, req.RemoteAddr)
 	debugf("[recv] GET %s/v1/keys/%s [%s]", e.url, key, req.RemoteAddr)
@@ -242,13 +222,7 @@ func GetHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
 	}
 	}
 
 
 	if body, err := command.Apply(r.Server); err != nil {
 	if body, err := command.Apply(r.Server); err != nil {
-
-		if _, ok := err.(store.NotFoundError); ok {
-			return newEtcdError(100, err.Error())
-		}
-
-		return newEtcdError(300, "")
-
+		return err
 	} else {
 	} else {
 		body, _ := body.([]byte)
 		body, _ := body.([]byte)
 		w.WriteHeader(http.StatusOK)
 		w.WriteHeader(http.StatusOK)
@@ -260,7 +234,7 @@ func GetHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
 }
 }
 
 
 // Watch handler
 // Watch handler
-func WatchHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
+func WatchHttpHandler(w http.ResponseWriter, req *http.Request) error {
 	key := req.URL.Path[len("/v1/watch/"):]
 	key := req.URL.Path[len("/v1/watch/"):]
 
 
 	command := &WatchCommand{
 	command := &WatchCommand{
@@ -279,7 +253,7 @@ func WatchHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
 
 
 		sinceIndex, err := strconv.ParseUint(string(content), 10, 64)
 		sinceIndex, err := strconv.ParseUint(string(content), 10, 64)
 		if err != nil {
 		if err != nil {
-			return newEtcdError(203, "Watch From Index")
+			return etcdErr.NewError(203, "Watch From Index")
 		}
 		}
 		command.SinceIndex = sinceIndex
 		command.SinceIndex = sinceIndex
 
 
@@ -289,7 +263,7 @@ func WatchHttpHandler(w http.ResponseWriter, req *http.Request) *etcdError {
 	}
 	}
 
 
 	if body, err := command.Apply(r.Server); err != nil {
 	if body, err := command.Apply(r.Server); err != nil {
-		return newEtcdError(500, key)
+		return etcdErr.NewError(500, key)
 	} else {
 	} else {
 		w.WriteHeader(http.StatusOK)
 		w.WriteHeader(http.StatusOK)
 
 

+ 3 - 3
raft_handlers.go

@@ -94,16 +94,16 @@ func EtcdURLHttpHandler(w http.ResponseWriter, req *http.Request) {
 }
 }
 
 
 // Response to the join request
 // Response to the join request
-func JoinHttpHandler(w http.ResponseWriter, req *http.Request) {
+func JoinHttpHandler(w http.ResponseWriter, req *http.Request) error {
 
 
 	command := &JoinCommand{}
 	command := &JoinCommand{}
 
 
 	if err := decodeJsonRequest(req, command); err == nil {
 	if err := decodeJsonRequest(req, command); err == nil {
 		debugf("Receive Join Request from %s", command.Name)
 		debugf("Receive Join Request from %s", command.Name)
-		dispatch(command, w, req, false)
+		return dispatch(command, w, req, false)
 	} else {
 	} else {
 		w.WriteHeader(http.StatusInternalServerError)
 		w.WriteHeader(http.StatusInternalServerError)
-		return
+		return nil
 	}
 	}
 }
 }
 
 

+ 9 - 10
raft_server.go

@@ -5,11 +5,11 @@ import (
 	"crypto/tls"
 	"crypto/tls"
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
+	etcdErr "github.com/coreos/etcd/error"
+	"github.com/coreos/go-raft"
 	"net/http"
 	"net/http"
 	"net/url"
 	"net/url"
 	"time"
 	"time"
-
-	"github.com/coreos/go-raft"
 )
 )
 
 
 type raftServer struct {
 type raftServer struct {
@@ -95,7 +95,7 @@ func (r *raftServer) ListenAndServe() {
 					}
 					}
 					err = joinCluster(r.Server, machine, r.tlsConf.Scheme)
 					err = joinCluster(r.Server, machine, r.tlsConf.Scheme)
 					if err != nil {
 					if err != nil {
-						if err.Error() == errors[103] {
+						if _, ok := err.(etcdErr.Error); ok {
 							fatal(err)
 							fatal(err)
 						}
 						}
 						debugf("cannot join to cluster via machine %s %s", machine, err)
 						debugf("cannot join to cluster via machine %s %s", machine, err)
@@ -148,7 +148,7 @@ func (r *raftServer) startTransport(scheme string, tlsConf tls.Config) {
 
 
 	// internal commands
 	// internal commands
 	raftMux.HandleFunc("/name", NameHttpHandler)
 	raftMux.HandleFunc("/name", NameHttpHandler)
-	raftMux.HandleFunc("/join", JoinHttpHandler)
+	raftMux.Handle("/join", errorHandler(JoinHttpHandler))
 	raftMux.HandleFunc("/vote", VoteHttpHandler)
 	raftMux.HandleFunc("/vote", VoteHttpHandler)
 	raftMux.HandleFunc("/log", GetLogHttpHandler)
 	raftMux.HandleFunc("/log", GetLogHttpHandler)
 	raftMux.HandleFunc("/log/append", AppendEntriesHttpHandler)
 	raftMux.HandleFunc("/log/append", AppendEntriesHttpHandler)
@@ -171,11 +171,7 @@ func joinCluster(s *raft.Server, raftURL string, scheme string) error {
 	json.NewEncoder(&b).Encode(newJoinCommand())
 	json.NewEncoder(&b).Encode(newJoinCommand())
 
 
 	// t must be ok
 	// t must be ok
-	t, ok := r.Transporter().(transporter)
-
-	if !ok {
-		panic("wrong type")
-	}
+	t, _ := r.Transporter().(transporter)
 
 
 	joinURL := url.URL{Host: raftURL, Scheme: scheme, Path: "/join"}
 	joinURL := url.URL{Host: raftURL, Scheme: scheme, Path: "/join"}
 
 
@@ -203,7 +199,10 @@ func joinCluster(s *raft.Server, raftURL string, scheme string) error {
 
 
 			} else if resp.StatusCode == http.StatusBadRequest {
 			} else if resp.StatusCode == http.StatusBadRequest {
 				debug("Reach max number machines in the cluster")
 				debug("Reach max number machines in the cluster")
-				return fmt.Errorf(errors[103])
+				decoder := json.NewDecoder(resp.Body)
+				err := &etcdErr.Error{}
+				decoder.Decode(err)
+				return *err
 			} else {
 			} else {
 				return fmt.Errorf("Unable to join")
 				return fmt.Errorf("Unable to join")
 			}
 			}

+ 0 - 25
store/error.go

@@ -1,25 +0,0 @@
-package store
-
-type NotFoundError string
-
-func (e NotFoundError) Error() string {
-	return string(e)
-}
-
-type NotFile string
-
-func (e NotFile) Error() string {
-	return string(e)
-}
-
-type TestFail string
-
-func (e TestFail) Error() string {
-	return string(e)
-}
-
-type Keyword string
-
-func (e Keyword) Error() string {
-	return string(e)
-}

+ 7 - 10
store/store.go

@@ -3,6 +3,7 @@ package store
 import (
 import (
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
+	etcdErr "github.com/coreos/etcd/error"
 	"path"
 	"path"
 	"strconv"
 	"strconv"
 	"sync"
 	"sync"
@@ -239,8 +240,7 @@ func (s *Store) internalSet(key string, value string, expireTime time.Time, inde
 		ok := s.Tree.set(key, Node{value, expireTime, update})
 		ok := s.Tree.set(key, Node{value, expireTime, update})
 
 
 		if !ok {
 		if !ok {
-			err := NotFile(key)
-			return nil, err
+			return nil, etcdErr.NewError(102, "set: "+key)
 		}
 		}
 
 
 		if isExpire {
 		if isExpire {
@@ -393,8 +393,7 @@ func (s *Store) RawGet(key string) ([]*Response, error) {
 		return resps, nil
 		return resps, nil
 	}
 	}
 
 
-	err := NotFoundError(key)
-	return nil, err
+	return nil, etcdErr.NewError(100, "get: "+key)
 }
 }
 
 
 func (s *Store) Delete(key string, index uint64) ([]byte, error) {
 func (s *Store) Delete(key string, index uint64) ([]byte, error) {
@@ -451,8 +450,7 @@ func (s *Store) internalDelete(key string, index uint64) ([]byte, error) {
 		return msg, err
 		return msg, err
 
 
 	} else {
 	} else {
-		err := NotFoundError(key)
-		return nil, err
+		return nil, etcdErr.NewError(100, "delete: "+key)
 	}
 	}
 }
 }
 
 
@@ -467,8 +465,7 @@ func (s *Store) TestAndSet(key string, prevValue string, value string, expireTim
 	resp := s.internalGet(key)
 	resp := s.internalGet(key)
 
 
 	if resp == nil {
 	if resp == nil {
-		err := NotFoundError(key)
-		return nil, err
+		return nil, etcdErr.NewError(100, "testandset: "+key)
 	}
 	}
 
 
 	if resp.Value == prevValue {
 	if resp.Value == prevValue {
@@ -478,8 +475,8 @@ func (s *Store) TestAndSet(key string, prevValue string, value string, expireTim
 	} else {
 	} else {
 
 
 		// If fails, return err
 		// If fails, return err
-		err := TestFail(fmt.Sprintf("TestAndSet: %s!=%s", resp.Value, prevValue))
-		return nil, err
+		return nil, etcdErr.NewError(101, fmt.Sprintf("TestAndSet: %s!=%s",
+			resp.Value, prevValue))
 	}
 	}
 
 
 }
 }

+ 0 - 1
third_party/github.com/coreos/go-etcd/examples/mutex/mutex.go

@@ -17,7 +17,6 @@ func main() {
 	c := etcd.NewClient()
 	c := etcd.NewClient()
 	c.Set("lock", "unlock", 0)
 	c.Set("lock", "unlock", 0)
 
 
-
 	for i := 0; i < 10; i++ {
 	for i := 0; i < 10; i++ {
 		go t(i, ch, etcd.NewClient())
 		go t(i, ch, etcd.NewClient())
 	}
 	}

+ 7 - 7
third_party/github.com/coreos/go-etcd/examples/speed/speed.go

@@ -1,8 +1,8 @@
-package main 
+package main
 
 
 import (
 import (
-	"github.com/coreos/go-etcd/etcd"
 	"fmt"
 	"fmt"
+	"github.com/coreos/go-etcd/etcd"
 	"time"
 	"time"
 )
 )
 
 
@@ -11,21 +11,21 @@ var count = 0
 func main() {
 func main() {
 	ch := make(chan bool, 10)
 	ch := make(chan bool, 10)
 	// set up a lock
 	// set up a lock
-	for i:=0; i < 100; i++ {
+	for i := 0; i < 100; i++ {
 		go t(i, ch, etcd.NewClient())
 		go t(i, ch, etcd.NewClient())
 	}
 	}
 	start := time.Now()
 	start := time.Now()
-	for i:=0; i< 100; i++ {
+	for i := 0; i < 100; i++ {
 		<-ch
 		<-ch
 	}
 	}
-	fmt.Println(time.Now().Sub(start), ": ", 100 * 50, "commands")
+	fmt.Println(time.Now().Sub(start), ": ", 100*50, "commands")
 }
 }
 
 
 func t(num int, ch chan bool, c *etcd.Client) {
 func t(num int, ch chan bool, c *etcd.Client) {
 	c.SyncCluster()
 	c.SyncCluster()
 	for i := 0; i < 50; i++ {
 	for i := 0; i < 50; i++ {
-		str := fmt.Sprintf("foo_%d",num * i)
+		str := fmt.Sprintf("foo_%d", num*i)
 		c.Set(str, "10", 0)
 		c.Set(str, "10", 0)
 	}
 	}
-	ch<-true
+	ch <- true
 }
 }

+ 3 - 3
web/web.go

@@ -29,12 +29,12 @@ func Start(raftServer *raft.Server, webURL string) {
 	webMux := http.NewServeMux()
 	webMux := http.NewServeMux()
 
 
 	server := &http.Server{
 	server := &http.Server{
-		Handler:   webMux,
-		Addr:      u.Host,
+		Handler: webMux,
+		Addr:    u.Host,
 	}
 	}
 
 
 	mainPage = &MainPage{
 	mainPage = &MainPage{
-		Leader: raftServer.Leader(),
+		Leader:  raftServer.Leader(),
 		Address: u.Host,
 		Address: u.Host,
 	}
 	}