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:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user