Fix health checker
This commit is contained in:
@@ -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{}))
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user