-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprobes.go
37 lines (31 loc) · 1.01 KB
/
probes.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
package foundation
import (
"fmt"
"io"
"net/http"
"github.com/rs/zerolog/log"
)
// InitLivenessAndReadiness initializes the /liveness and /readiness endpoint on port 5000
func InitLivenessAndReadiness() {
InitLivenessAndReadinessWithPort(5000)
}
// InitLivenessAndReadinessWithPort initializes the /liveness and /readiness endpoint on specified port
func InitLivenessAndReadinessWithPort(port int) {
// start liveness endpoint
go func() {
portString := fmt.Sprintf(":%v", port)
log.Debug().
Str("port", portString).
Msg("Serving /liveness and /readiness endpoints...")
serverMux := http.NewServeMux()
serverMux.HandleFunc("/liveness", func(w http.ResponseWriter, _ *http.Request) {
io.WriteString(w, "I'm alive!\n")
})
serverMux.HandleFunc("/readiness", func(w http.ResponseWriter, _ *http.Request) {
io.WriteString(w, "I'm ready!\n")
})
if err := http.ListenAndServe(portString, serverMux); err != nil {
log.Fatal().Err(err).Msg("Starting /liveness and /readiness listener failed")
}
}()
}