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:
Maxime Delporte
2025-10-09 21:38:00 +02:00
parent a90b5305af
commit 4047888eb0
8 changed files with 152 additions and 0 deletions

23
cmd/api/healthcheck.go Normal file
View 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)
}