Cleanup code

This changes variable names that were abbreviations, uses more constants
from the net/http package and improves the json decoding / encoding.
This commit is contained in:
Felix Auringer
2021-04-27 08:47:11 +02:00
parent 78668ad430
commit 712d0e6420
4 changed files with 17 additions and 14 deletions

View File

@@ -6,14 +6,14 @@ import (
"net/http"
)
// Health sends the response that the API works. If it
// it is able to do so, it is obviously correct.
// Health tries to respond that the server is alive.
// If it is not, the response won't reach the client.
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)
log.Printf("JSON marshal error in health route: %v\n", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
if _, err := w.Write(response); err != nil {