etcd/etcd_server.go

42 lines
851 B
Go
Raw Normal View History

2013-08-15 01:45:47 +04:00
package main
import (
"net/http"
)
type etcdServer struct {
2013-08-15 03:27:52 +04:00
http.Server
2013-08-15 01:45:47 +04:00
name string
url string
tlsConf *TLSConfig
tlsInfo *TLSInfo
}
var e *etcdServer
func newEtcdServer(name string, urlStr string, listenHost string, tlsConf *TLSConfig, tlsInfo *TLSInfo) *etcdServer {
2013-08-15 01:45:47 +04:00
return &etcdServer{
2013-08-15 03:27:52 +04:00
Server: http.Server{
Handler: NewEtcdMuxer(),
TLSConfig: &tlsConf.Server,
Addr: listenHost,
2013-08-15 03:27:52 +04:00
},
2013-08-15 01:45:47 +04:00
name: name,
2013-08-15 03:27:52 +04:00
url: urlStr,
2013-08-15 01:45:47 +04:00
tlsConf: tlsConf,
tlsInfo: tlsInfo,
}
}
// Start to listen and response etcd client command
2013-08-15 04:58:00 +04:00
func (e *etcdServer) ListenAndServe() {
2013-08-15 01:45:47 +04:00
2013-09-09 04:48:33 +04:00
infof("etcd server [name %s, listen on %s, advertised url %s]", e.name, e.Server.Addr, e.url)
2013-08-15 01:45:47 +04:00
if e.tlsConf.Scheme == "http" {
2013-08-15 04:58:00 +04:00
fatal(e.Server.ListenAndServe())
2013-08-15 01:45:47 +04:00
} else {
2013-08-15 04:58:00 +04:00
fatal(e.Server.ListenAndServeTLS(e.tlsInfo.CertFile, e.tlsInfo.KeyFile))
2013-08-15 01:45:47 +04:00
}
}