Creating Makefile. Adding .idea files. Updating main.go : Configuration of the application and the server. Creating our first handler for the endpoint /v1/healthcheck with healtcheck.go file.
This commit is contained in:
23
cmd/api/healthcheck.go
Normal file
23
cmd/api/healthcheck.go
Normal file
@@ -0,0 +1,23 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user