Added /health endpoint
This commit is contained in:
@@ -17,6 +17,10 @@ type ApiResponse struct {
|
|||||||
Form map[string]string `json:"form"`
|
Form map[string]string `json:"form"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HealthResponse struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
var resp ApiResponse
|
var resp ApiResponse
|
||||||
@@ -54,6 +58,22 @@ func main() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
resp := HealthResponse{Status: "ok"}
|
||||||
|
|
||||||
|
b, err := json.Marshal(&resp)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = w.Write(b)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
fmt.Println("Listening on localhost:8080")
|
fmt.Println("Listening on localhost:8080")
|
||||||
log.Fatal(http.ListenAndServe("localhost:8080", nil))
|
log.Fatal(http.ListenAndServe("localhost:8080", nil))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user