aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/google.golang.org/grpc/health/health.go
diff options
context:
space:
mode:
authorNathan Dench <ndenc2@gmail.com>2019-05-24 15:16:44 +1000
committerNathan Dench <ndenc2@gmail.com>2019-05-24 15:16:44 +1000
commit107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch)
treeca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/google.golang.org/grpc/health/health.go
parent844b5a68d8af4791755b8f0ad293cc99f5959183 (diff)
downloadterraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz
terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst
terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip
Upgrade to 0.12
Diffstat (limited to 'vendor/google.golang.org/grpc/health/health.go')
-rw-r--r--vendor/google.golang.org/grpc/health/health.go70
1 files changed, 0 insertions, 70 deletions
diff --git a/vendor/google.golang.org/grpc/health/health.go b/vendor/google.golang.org/grpc/health/health.go
deleted file mode 100644
index 4dccbc7..0000000
--- a/vendor/google.golang.org/grpc/health/health.go
+++ /dev/null
@@ -1,70 +0,0 @@
1/*
2 *
3 * Copyright 2017 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19// Package health provides some utility functions to health-check a server. The implementation
20// is based on protobuf. Users need to write their own implementations if other IDLs are used.
21package health
22
23import (
24 "sync"
25
26 "golang.org/x/net/context"
27 "google.golang.org/grpc"
28 "google.golang.org/grpc/codes"
29 healthpb "google.golang.org/grpc/health/grpc_health_v1"
30)
31
32// Server implements `service Health`.
33type Server struct {
34 mu sync.Mutex
35 // statusMap stores the serving status of the services this Server monitors.
36 statusMap map[string]healthpb.HealthCheckResponse_ServingStatus
37}
38
39// NewServer returns a new Server.
40func NewServer() *Server {
41 return &Server{
42 statusMap: make(map[string]healthpb.HealthCheckResponse_ServingStatus),
43 }
44}
45
46// Check implements `service Health`.
47func (s *Server) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
48 s.mu.Lock()
49 defer s.mu.Unlock()
50 if in.Service == "" {
51 // check the server overall health status.
52 return &healthpb.HealthCheckResponse{
53 Status: healthpb.HealthCheckResponse_SERVING,
54 }, nil
55 }
56 if status, ok := s.statusMap[in.Service]; ok {
57 return &healthpb.HealthCheckResponse{
58 Status: status,
59 }, nil
60 }
61 return nil, grpc.Errorf(codes.NotFound, "unknown service")
62}
63
64// SetServingStatus is called when need to reset the serving status of a service
65// or insert a new service entry into the statusMap.
66func (s *Server) SetServingStatus(service string, status healthpb.HealthCheckResponse_ServingStatus) {
67 s.mu.Lock()
68 s.statusMap[service] = status
69 s.mu.Unlock()
70}