-
Malte Bauch authoredMalte Bauch authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
http.go 982 B
package gosdn
import (
"context"
"fmt"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)
func stopHttpServer() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
log.Info("shutting down http server")
return c.httpServer.Shutdown(ctx)
}
func registerHttpHandler() {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in f", r)
}
}()
http.HandleFunc("/livez", healthCheck)
http.HandleFunc("/readyz", readynessCheck)
http.Handle("/metrics", promhttp.Handler())
}
func startHttpServer() {
registerHttpHandler()
c.httpServer = &http.Server{Addr: ":8080"}
go func() {
log.Info(c.httpServer.ListenAndServe())
}()
}
func healthCheck(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(http.StatusOK)
}
func readynessCheck(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(http.StatusOK)
}