36 lines
792 B
Go
36 lines
792 B
Go
|
|
package health
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
log "github.com/sirupsen/logrus"
|
||
|
|
pb "myschools.me/suguo/consul-demo/proto"
|
||
|
|
)
|
||
|
|
|
||
|
|
//Server 微服务
|
||
|
|
type Server struct {
|
||
|
|
}
|
||
|
|
|
||
|
|
//Check 实现微服务接口
|
||
|
|
func (s *Server) Check(c context.Context, req *pb.HealthCheckRequest) (*pb.HealthCheckResponse, error) {
|
||
|
|
log.WithFields(log.Fields{
|
||
|
|
"func": "Check",
|
||
|
|
}).Infof("%s %s", req.Service, req.GetService())
|
||
|
|
resp := &pb.HealthCheckResponse{
|
||
|
|
Status: pb.HealthCheckResponse_SERVING,
|
||
|
|
}
|
||
|
|
return resp, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
//Watch 实现微服务接口stream
|
||
|
|
func (s *Server) Watch(req *pb.HealthCheckRequest, out pb.Health_WatchServer) error {
|
||
|
|
log.WithFields(log.Fields{
|
||
|
|
"func": "Watch",
|
||
|
|
}).Infof("%s", req.GetService())
|
||
|
|
out.Send(&pb.HealthCheckResponse{
|
||
|
|
Status: pb.HealthCheckResponse_SERVING,
|
||
|
|
})
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|