Add health route
This commit is contained in:
23
api/health.go
Normal file
23
api/health.go
Normal file
@ -0,0 +1,23 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Health sends the response that the API works. If it
|
||||
// it is able to do so, it is obviously correct.
|
||||
func Health(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
response, err := json.Marshal(Message{"I'm alive!"})
|
||||
if err != nil {
|
||||
log.Printf("Error formatting the health route: %v\n", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if _, err := w.Write(response); err != nil {
|
||||
log.Printf("Error handling the health route: %v\n", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
5
api/response_messages.go
Normal file
5
api/response_messages.go
Normal file
@ -0,0 +1,5 @@
|
||||
package api
|
||||
|
||||
type Message struct {
|
||||
Msg string `json:"msg"`
|
||||
}
|
Reference in New Issue
Block a user