greenlight/cmd/api/healthcheck.go

31 lines
606 B
Go

package main
import (
"encoding/json"
"net/http"
)
func (app *application) healthCheckHandler(w http.ResponseWriter, r *http.Request) {
// create a mapping that will be converted to json
data := map[string]string{
"status": "available",
"environment": app.config.env,
"version": version,
}
js, err := json.Marshal(data)
if err != nil {
app.logger.Print(err)
http.Error(w, "the server encountered an error and could process your request", http.StatusInternalServerError)
return
}
js = append(js, '\n')
w.Header().Set("Content-Type", "application/json")
w.Write(js)
}