Fix health checker

This commit is contained in:
Asim
2015-05-21 23:06:01 +01:00
parent c9df1cf7d2
commit d67c1ba111
5 changed files with 61 additions and 17 deletions

View File

@@ -1,21 +1,17 @@
package server
import (
"io"
"net/http"
"net/url"
"github.com/myodc/go-micro/proto/health"
"golang.org/x/net/context"
)
func registerHealthChecker(mux *http.ServeMux) {
req := &http.Request{
Method: "GET",
URL: &url.URL{
Path: HealthPath,
},
}
if _, path := mux.Handler(req); path != HealthPath {
mux.HandleFunc(HealthPath, func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "ok")
})
}
type Debug struct{}
func (d *Debug) Health(ctx context.Context, req *health.Request, rsp *health.Response) error {
rsp.Status = "ok"
return nil
}
func registerHealthChecker(r Server) {
r.Register(r.NewReceiver(&Debug{}))
}

View File

@@ -2,7 +2,6 @@ package server
import (
"bytes"
"net/http"
"sync"
log "github.com/golang/glog"
@@ -97,7 +96,7 @@ func (s *RpcServer) Register(r Receiver) error {
}
func (s *RpcServer) Start() error {
registerHealthChecker(http.DefaultServeMux)
registerHealthChecker(s)
ts, err := s.opts.transport.Listen(s.address)
if err != nil {