This commit is contained in:
Xiang Li 2013-08-13 12:17:19 -07:00
parent 82fe001c65
commit b71811375b
2 changed files with 9 additions and 17 deletions

11
etcd.go
View File

@ -250,13 +250,6 @@ func dialTimeout(network, addr string) (net.Conn, error) {
return net.DialTimeout(network, addr, HTTPTimeout) return net.DialTimeout(network, addr, HTTPTimeout)
} }
type Etcd struct {
http.Server
url string
scheme string
tls TLSConfig
}
// Start to listen and response client command // Start to listen and response client command
func startEtcdTransport(info Info, scheme string, tlsConf tls.Config) { func startEtcdTransport(info Info, scheme string, tlsConf tls.Config) {
u, err := url.Parse(info.EtcdURL) u, err := url.Parse(info.EtcdURL)
@ -265,12 +258,10 @@ func startEtcdTransport(info Info, scheme string, tlsConf tls.Config) {
} }
infof("etcd server [%s:%s]", info.Name, u) infof("etcd server [%s:%s]", info.Name, u)
server := &Etcd{ server := http.Server{
Server: http.Server{
Handler: NewEtcdMuxer(), Handler: NewEtcdMuxer(),
TLSConfig: &tlsConf, TLSConfig: &tlsConf,
Addr: u.Host, Addr: u.Host,
},
} }
if scheme == "http" { if scheme == "http" {

View File

@ -165,8 +165,9 @@ func dispatch(c Command, w *http.ResponseWriter, req *http.Request, etcd bool) {
return return
} }
} else { } else {
leader := raftServer.Leader()
// current no leader // current no leader
if raftServer.Leader() == "" { if leader == "" {
(*w).WriteHeader(http.StatusInternalServerError) (*w).WriteHeader(http.StatusInternalServerError)
(*w).Write(newJsonError(300, "")) (*w).Write(newJsonError(300, ""))
return return
@ -179,10 +180,10 @@ func dispatch(c Command, w *http.ResponseWriter, req *http.Request, etcd bool) {
var url string var url string
if etcd { if etcd {
etcdAddr, _ := nameToEtcdURL(raftServer.Leader()) etcdAddr, _ := nameToEtcdURL(leader)
url = etcdAddr + path url = etcdAddr + path
} else { } else {
raftAddr, _ := nameToRaftURL(raftServer.Leader()) raftAddr, _ := nameToRaftURL(leader)
url = raftAddr + path url = raftAddr + path
} }