-
Notifications
You must be signed in to change notification settings - Fork 289
/
Copy pathhealth.go
38 lines (30 loc) · 933 Bytes
/
health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package health
import (
"context"
"net/http"
pbs "github.com/hashicorp/boundary/internal/gen/controller/ops/services"
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
)
type Service struct {
pbs.UnimplementedHealthServiceServer
replyWithServiceUnavailable bool
}
func NewService() *Service {
s := Service{}
return &s
}
func (s *Service) GetHealth(ctx context.Context, req *pbs.GetHealthRequest) (*pbs.GetHealthResponse, error) {
if s.replyWithServiceUnavailable {
err := handlers.SetStatusCode(ctx, http.StatusServiceUnavailable)
if err != nil {
return nil, err
}
return &pbs.GetHealthResponse{}, nil
}
return &pbs.GetHealthResponse{}, nil
}
// StartServiceUnavailableReplies gets returned to the caller of NewService.
// When invoked, we start responding to any health queries with a 503.
func (s *Service) StartServiceUnavailableReplies() {
s.replyWithServiceUnavailable = true
}