Fix health checker
This commit is contained in:
parent
c9df1cf7d2
commit
d67c1ba111
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/myodc/go-micro/broker"
|
||||
"github.com/myodc/go-micro/client"
|
||||
"github.com/myodc/go-micro/registry"
|
||||
"github.com/myodc/go-micro/server"
|
||||
"github.com/myodc/go-micro/store"
|
||||
@ -113,6 +114,8 @@ func Setup(c *cli.Context) error {
|
||||
transport.DefaultTransport = transport.NewNatsTransport(tAddrs)
|
||||
}
|
||||
|
||||
client.DefaultClient = client.NewRpcClient()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
38
proto/health/health.pb.go
Normal file
38
proto/health/health.pb.go
Normal file
@ -0,0 +1,38 @@
|
||||
// Code generated by protoc-gen-go.
|
||||
// source: github.com/myodc/go-micro/proto/health/health.proto
|
||||
// DO NOT EDIT!
|
||||
|
||||
/*
|
||||
Package health is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
github.com/myodc/go-micro/proto/health/health.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Request
|
||||
Response
|
||||
*/
|
||||
package health
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
func (m *Request) Reset() { *m = Request{} }
|
||||
func (m *Request) String() string { return proto.CompactTextString(m) }
|
||||
func (*Request) ProtoMessage() {}
|
||||
|
||||
type Response struct {
|
||||
Status string `protobuf:"bytes,1,opt,name=status" json:"status,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Response) Reset() { *m = Response{} }
|
||||
func (m *Response) String() string { return proto.CompactTextString(m) }
|
||||
func (*Response) ProtoMessage() {}
|
||||
|
||||
func init() {
|
||||
}
|
8
proto/health/health.proto
Normal file
8
proto/health/health.proto
Normal file
@ -0,0 +1,8 @@
|
||||
syntax = "proto3";
|
||||
|
||||
message Request {
|
||||
}
|
||||
|
||||
message Response {
|
||||
string status = 1;
|
||||
}
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user