This commit is contained in:
lbenedar
2026-03-10 15:39:45 +03:00
parent 281bc33897
commit 1d7beb7de4
3 changed files with 12 additions and 8 deletions

View File

@@ -5,12 +5,14 @@ import (
)
func (app *application) healthcheckHandler(w http.ResponseWriter, r *http.Request) {
data := map[string]string{
"status": "available",
"environment": app.config.env,
"version": version,
env := envelope{
"status": "available",
"system_info": map[string]string{
"environment": app.config.env,
"version": version,
},
}
err := app.writeJSON(w, http.StatusOK, data, nil)
err := app.writeJSON(w, http.StatusOK, env, nil)
if err != nil {
app.logger.Print(err)
http.Error(w, "The server encountered a problem and could not process your request", http.StatusInternalServerError)

View File

@@ -9,6 +9,8 @@ import (
"github.com/julienschmidt/httprouter"
)
type envelope map[string]any
func (app *application) readIDParam(r *http.Request) (int64, error) {
params := httprouter.ParamsFromContext(r.Context())
@@ -19,8 +21,8 @@ func (app *application) readIDParam(r *http.Request) (int64, error) {
return id, nil
}
func (app *application) writeJSON(w http.ResponseWriter, status int, data any, headers http.Header) error {
js, err := json.Marshal(data)
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
}

View File

@@ -28,7 +28,7 @@ func (app *application) showMovieHandler(w http.ResponseWriter, r *http.Request)
Version: 1,
}
err = app.writeJSON(w, http.StatusOK, movie, nil)
err = app.writeJSON(w, http.StatusOK, envelope{"movie": movie}, nil)
if err != nil {
app.logger.Print(err)
http.Error(w, "The server encountered a problem and could not process your request", http.StatusInternalServerError)