add healthcheck route

This commit is contained in:
lbenedar
2026-04-10 18:34:01 +03:00
parent a465e6a657
commit cd204ebcf5
7 changed files with 94 additions and 20 deletions

24
cmd/api/errors.go Normal file
View File

@@ -0,0 +1,24 @@
package main
import "net/http"
func (app *application) logError(r *http.Request, err error) {
app.slogger.Error(err.Error(), "request_method", r.Method, "request_url", r.URL.String())
}
func (app *application) errorResponse(w http.ResponseWriter, r *http.Request, status int, message any) {
env := envelope{"error": message}
err := app.writeJSON(w, status, env, nil)
if err != nil {
app.logError(r, err)
w.WriteHeader(500)
}
}
func (app *application) serverErrorResponse(w http.ResponseWriter, r *http.Request, err error) {
app.logError(r, err)
message := "the server encountered a problem and could not process your request"
app.errorResponse(w, r, http.StatusInternalServerError, message)
}