增加微服务必用的健康检查

This commit is contained in:
suguo.yao 2021-09-16 09:21:51 +08:00
parent 1e5ea70247
commit 553f2391c7
2 changed files with 34 additions and 5 deletions

11
go.mod
View File

@ -9,8 +9,9 @@ require (
google.golang.org/grpc v1.40.0
gorm.io/driver/mysql v1.1.2
gorm.io/driver/sqlite v1.1.4
gorm.io/gorm v1.21.14
gorm.io/gorm v1.21.15
gorm.io/plugin/dbresolver v1.1.0
myschools.me/wodeschool/ws-base v1.0.7
)
require (
@ -22,7 +23,7 @@ require (
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.6.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-hclog v0.12.0 // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
@ -44,12 +45,12 @@ require (
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/ugorji/go/codec v1.1.13 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/protobuf v1.26.0 // indirect
google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect

28
server/health-server.go Normal file
View File

@ -0,0 +1,28 @@
package server
import (
"context"
health "myschools.me/wodeschool/ws-base/health"
)
//Server consul心跳处理
type Health struct {
}
//Check 实现微服务接口
func (h *Health) Check(ctx context.Context, req *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
resp := &health.HealthCheckResponse{
Status: health.HealthCheckResponse_SERVING,
}
return resp, nil
}
//Watch 实现微服务接口stream
func (h *Health) Watch(req *health.HealthCheckRequest, out health.Health_WatchServer) error {
out.Send(&health.HealthCheckResponse{
Status: health.HealthCheckResponse_SERVING,
})
return nil
}