Skip to content

Instantly share code, notes, and snippets.

@nkreiger
Created December 28, 2020 16:13
Show Gist options
  • Save nkreiger/682ba1a04c9a3e082abba7ea28ece048 to your computer and use it in GitHub Desktop.
Save nkreiger/682ba1a04c9a3e082abba7ea28ece048 to your computer and use it in GitHub Desktop.
general health api endpoint handler
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