mirror of
https://github.com/openfaas/faas.git
synced 2025-06-09 00:36:46 +00:00
Move /healthz handler to handlers package
Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
This commit is contained in:
parent
40dbede065
commit
b87ecde60f
20
gateway/handlers/healthhandler.go
Normal file
20
gateway/handlers/healthhandler.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (c) OpenFaaS Author(s) 2019. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
|
package handlers
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
//HealthzHandler healthz hanlder for mertics server
|
||||||
|
func HealthzHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
switch r.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Write([]byte("OK"))
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
@ -232,11 +232,11 @@ func runMetricsServer() {
|
|||||||
metricsHandler := metrics.PrometheusHandler()
|
metricsHandler := metrics.PrometheusHandler()
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.Handle("/metrics", metricsHandler)
|
router.Handle("/metrics", metricsHandler)
|
||||||
router.HandleFunc("/healthz", healthzHandler)
|
router.HandleFunc("/healthz", handlers.HealthzHandler)
|
||||||
|
|
||||||
port := 8082
|
port := 8082
|
||||||
readTimeout := time.Duration(5) * time.Second
|
readTimeout := 5 * time.Second
|
||||||
writeTimeout := time.Duration(5) * time.Second
|
writeTimeout := 5 * time.Second
|
||||||
|
|
||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
Addr: fmt.Sprintf(":%d", port),
|
Addr: fmt.Sprintf(":%d", port),
|
||||||
@ -248,16 +248,3 @@ func runMetricsServer() {
|
|||||||
|
|
||||||
log.Fatal(s.ListenAndServe())
|
log.Fatal(s.ListenAndServe())
|
||||||
}
|
}
|
||||||
|
|
||||||
func healthzHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
switch r.Method {
|
|
||||||
case http.MethodGet:
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
w.Write([]byte("OK"))
|
|
||||||
break
|
|
||||||
|
|
||||||
default:
|
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user