Files
greenlight/cmd/api/healthcheck.go

24 lines
815 B
Go

package main
import (
"fmt"
"net/http"
)
/*
Declare a handler which writes a plain-text response with information about the
application status, operating environment and version
*/
/*
Tips: The important thing to point out here is that healthcheckHandler is implemented as a method
on our application struct. This is an effective and idiomatic way to make dependencies available
to our handlers without resorting to global variables or closures - any dependency that the
healthcheckHandler needs can simply be included as a field in the application struct when we
initialize it in main()
*/
func (app *application) healthcheckHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "status: available")
fmt.Fprintf(w, "environment: %s\n", app.config.env)
fmt.Fprintf(w, "version: %s\n", version)
}