-
Notifications
You must be signed in to change notification settings - Fork 5
/
service.go
36 lines (31 loc) · 934 Bytes
/
service.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
package health
import (
"fmt"
"github.com/Keyfactor/ejbca-k8s-csr-signer/pkg/logger"
"github.com/valyala/fasthttp"
)
var (
healthLog = logger.Register("CertificateSigner-Handler")
)
// ServiceHealthCheck create a health check service
type ServiceHealthCheck struct {
Addr string
}
// Serve start listen health check
func (s *ServiceHealthCheck) Serve() error {
address := fmt.Sprintf("[::]:%s", s.Addr)
healthLog.Infof("Starting health check service at: %v", address)
if err := fasthttp.ListenAndServe(address, fasthttp.CompressHandler(s.requestHandler)); err != nil {
healthLog.Fatalf("Error in ListenAndServe: %s", err)
return fmt.Errorf("Error in ListenAndServe: %s", err)
}
return nil
}
func (s *ServiceHealthCheck) requestHandler(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(fasthttp.StatusOK)
_, err := fmt.Fprintf(ctx, "OK!")
if err != nil {
return
}
ctx.SetContentType("text/plain; charset=utf8")
}