*: golint
This commit is contained in:
@ -6,6 +6,7 @@ go:
|
|||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- go get golang.org/x/tools/cmd/goimports
|
- go get golang.org/x/tools/cmd/goimports
|
||||||
|
- go get github.com/golang/lint/golint
|
||||||
- go get github.com/axw/gocov/gocov
|
- go get github.com/axw/gocov/gocov
|
||||||
- go get github.com/mattn/goveralls
|
- go get github.com/mattn/goveralls
|
||||||
- go get golang.org/x/tools/cmd/cover
|
- go get golang.org/x/tools/cmd/cover
|
||||||
@ -17,4 +18,5 @@ install:
|
|||||||
script:
|
script:
|
||||||
- '! gofmt -s -d -l . 2>&1 | read'
|
- '! gofmt -s -d -l . 2>&1 | read'
|
||||||
- '! goimports -l . | read'
|
- '! goimports -l . | read'
|
||||||
|
- '! golint ./... | grep -vE "(_string|\.pb)\.go:"'
|
||||||
- make test testrace
|
- make test testrace
|
||||||
|
@ -11,19 +11,22 @@ import (
|
|||||||
healthpb "google.golang.org/grpc/health/grpc_health_v1"
|
healthpb "google.golang.org/grpc/health/grpc_health_v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HealthServer struct {
|
// Server implements `service Health`.
|
||||||
|
type Server struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
// statusMap stores the serving status of the services this HealthServer monitors.
|
// statusMap stores the serving status of the services this Server monitors.
|
||||||
statusMap map[string]healthpb.HealthCheckResponse_ServingStatus
|
statusMap map[string]healthpb.HealthCheckResponse_ServingStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHealthServer() *HealthServer {
|
// NewServer returns a new Server.
|
||||||
return &HealthServer{
|
func NewServer() *Server {
|
||||||
|
return &Server{
|
||||||
statusMap: make(map[string]healthpb.HealthCheckResponse_ServingStatus),
|
statusMap: make(map[string]healthpb.HealthCheckResponse_ServingStatus),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HealthServer) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
|
// Check implements `service Health`.
|
||||||
|
func (s *Server) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
if in.Service == "" {
|
if in.Service == "" {
|
||||||
@ -42,7 +45,7 @@ func (s *HealthServer) Check(ctx context.Context, in *healthpb.HealthCheckReques
|
|||||||
|
|
||||||
// SetServingStatus is called when need to reset the serving status of a service
|
// SetServingStatus is called when need to reset the serving status of a service
|
||||||
// or insert a new service entry into the statusMap.
|
// or insert a new service entry into the statusMap.
|
||||||
func (s *HealthServer) SetServingStatus(service string, status healthpb.HealthCheckResponse_ServingStatus) {
|
func (s *Server) SetServingStatus(service string, status healthpb.HealthCheckResponse_ServingStatus) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
s.statusMap[service] = status
|
s.statusMap[service] = status
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
|
@ -371,7 +371,7 @@ type test struct {
|
|||||||
|
|
||||||
// Configurable knobs, after newTest returns:
|
// Configurable knobs, after newTest returns:
|
||||||
testServer testpb.TestServiceServer // nil means none
|
testServer testpb.TestServiceServer // nil means none
|
||||||
healthServer *health.HealthServer // nil means disabled
|
healthServer *health.Server // nil means disabled
|
||||||
maxStream uint32
|
maxStream uint32
|
||||||
userAgent string
|
userAgent string
|
||||||
clientCompression bool
|
clientCompression bool
|
||||||
@ -748,7 +748,7 @@ func TestHealthCheckOnSuccess(t *testing.T) {
|
|||||||
|
|
||||||
func testHealthCheckOnSuccess(t *testing.T, e env) {
|
func testHealthCheckOnSuccess(t *testing.T, e env) {
|
||||||
te := newTest(t, e)
|
te := newTest(t, e)
|
||||||
hs := health.NewHealthServer()
|
hs := health.NewServer()
|
||||||
hs.SetServingStatus("grpc.health.v1.Health", 1)
|
hs.SetServingStatus("grpc.health.v1.Health", 1)
|
||||||
te.healthServer = hs
|
te.healthServer = hs
|
||||||
te.startServer(&testServer{security: e.security})
|
te.startServer(&testServer{security: e.security})
|
||||||
@ -774,7 +774,7 @@ func testHealthCheckOnFailure(t *testing.T, e env) {
|
|||||||
"Failed to dial ",
|
"Failed to dial ",
|
||||||
"grpc: the client connection is closing; please retry",
|
"grpc: the client connection is closing; please retry",
|
||||||
)
|
)
|
||||||
hs := health.NewHealthServer()
|
hs := health.NewServer()
|
||||||
hs.SetServingStatus("grpc.health.v1.HealthCheck", 1)
|
hs.SetServingStatus("grpc.health.v1.HealthCheck", 1)
|
||||||
te.healthServer = hs
|
te.healthServer = hs
|
||||||
te.startServer(&testServer{security: e.security})
|
te.startServer(&testServer{security: e.security})
|
||||||
@ -818,7 +818,7 @@ func TestHealthCheckServingStatus(t *testing.T) {
|
|||||||
|
|
||||||
func testHealthCheckServingStatus(t *testing.T, e env) {
|
func testHealthCheckServingStatus(t *testing.T, e env) {
|
||||||
te := newTest(t, e)
|
te := newTest(t, e)
|
||||||
hs := health.NewHealthServer()
|
hs := health.NewServer()
|
||||||
te.healthServer = hs
|
te.healthServer = hs
|
||||||
te.startServer(&testServer{security: e.security})
|
te.startServer(&testServer{security: e.security})
|
||||||
defer te.tearDown()
|
defer te.tearDown()
|
||||||
|
Reference in New Issue
Block a user