feat: logger, middleware
This commit is contained in:
@@ -15,14 +15,17 @@ func (app *application) failedValidationResponse(w http.ResponseWriter, r *http.
|
||||
// book we'll upgrade this to use structured logging, and record additional information
|
||||
// about the request including the HTTP method and URL.
|
||||
func (app *application) logError(r *http.Request, err error) {
|
||||
app.logger.Println(err)
|
||||
app.logger.PrintError(err, map[string]string{
|
||||
"request_method": r.Method,
|
||||
"request_url": r.URL.String(),
|
||||
})
|
||||
}
|
||||
|
||||
// The errorResponse() method is a generic helper for sending JSON-formatted error
|
||||
// messages to the client with a given status code. Note that we're using an interface{}
|
||||
// type for the message parameter, rather than just a string type, as this gives us
|
||||
// more flexibility over the values that we can include in the response.
|
||||
func (app *application) errorResponse(w http.ResponseWriter, r *http.Request, status int, message interface{}) {
|
||||
func (app *application) errorResponse(w http.ResponseWriter, r *http.Request, status int, message any) {
|
||||
env := envelope{"error": message}
|
||||
|
||||
// Write the response using the writeJSON() helper. If this happens to return an
|
||||
|
||||
Reference in New Issue
Block a user