Created
December 28, 2020 16:13
-
-
Save nkreiger/682ba1a04c9a3e082abba7ea28ece048 to your computer and use it in GitHub Desktop.
general health api endpoint handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package services | |
import ( | |
"encoding/json" | |
"log" | |
"net/http" | |
) | |
type status struct { | |
Message string `json:"message"` | |
} | |
// Health returns the health of the API | |
var Health = func(w http.ResponseWriter, r *http.Request) { | |
(w).Header().Set("Content-Type", "application/json") | |
log.Println("Health probe received") | |
output := status{ | |
Message: "Health Probe Successful", | |
} | |
data, err := json.MarshalIndent(output, "", "\t") | |
if err != nil { | |
log.Printf("error encoding json: %s", data) | |
} | |
_, err = w.Write(data) | |
if err != nil { | |
log.Printf("error writing response to user: %v", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment