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

25
cmd/api/helpers.go Normal file
View File

@@ -0,0 +1,25 @@
package main
import (
"encoding/json"
"net/http"
)
type envelope map[string]any
func (app *application) writeJSON(w http.ResponseWriter, status int, data envelope, headers http.Header) error {
js, err := json.MarshalIndent(data, "", "\t")
if err != nil {
return err
}
js = append(js, '\n')
for key, value := range headers {
w.Header()[key] = value
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
w.Write(js)
return nil
}