Fix health checker
This commit is contained in:
parent
c9df1cf7d2
commit
d67c1ba111
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/myodc/go-micro/broker"
|
"github.com/myodc/go-micro/broker"
|
||||||
|
"github.com/myodc/go-micro/client"
|
||||||
"github.com/myodc/go-micro/registry"
|
"github.com/myodc/go-micro/registry"
|
||||||
"github.com/myodc/go-micro/server"
|
"github.com/myodc/go-micro/server"
|
||||||
"github.com/myodc/go-micro/store"
|
"github.com/myodc/go-micro/store"
|
||||||
@ -113,6 +114,8 @@ func Setup(c *cli.Context) error {
|
|||||||
transport.DefaultTransport = transport.NewNatsTransport(tAddrs)
|
transport.DefaultTransport = transport.NewNatsTransport(tAddrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.DefaultClient = client.NewRpcClient()
|
||||||
|
|
||||||
return nil
|
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
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"github.com/myodc/go-micro/proto/health"
|
||||||
"net/http"
|
"golang.org/x/net/context"
|
||||||
"net/url"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func registerHealthChecker(mux *http.ServeMux) {
|
type Debug struct{}
|
||||||
req := &http.Request{
|
|
||||||
Method: "GET",
|
func (d *Debug) Health(ctx context.Context, req *health.Request, rsp *health.Response) error {
|
||||||
URL: &url.URL{
|
rsp.Status = "ok"
|
||||||
Path: HealthPath,
|
return nil
|
||||||
},
|
|
||||||
}
|
|
||||||
if _, path := mux.Handler(req); path != HealthPath {
|
|
||||||
mux.HandleFunc(HealthPath, func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
io.WriteString(w, "ok")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func registerHealthChecker(r Server) {
|
||||||
|
r.Register(r.NewReceiver(&Debug{}))
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"net/http"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
log "github.com/golang/glog"
|
log "github.com/golang/glog"
|
||||||
@ -97,7 +96,7 @@ func (s *RpcServer) Register(r Receiver) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *RpcServer) Start() error {
|
func (s *RpcServer) Start() error {
|
||||||
registerHealthChecker(http.DefaultServeMux)
|
registerHealthChecker(s)
|
||||||
|
|
||||||
ts, err := s.opts.transport.Listen(s.address)
|
ts, err := s.opts.transport.Listen(s.address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user