You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
r:=chi.NewRouter()
r.Use(middleware.RequestID)
r.Use(middleware.Logger)
r.Use(middleware.Timeout(10*time.Second))
// NOTE: auth middleware can go herer.Use(middleware.Recoverer)
// -- Map uri to handler funcr.Route(baseUri, func(r chi.Router) {
// NOTE: these routes all have baseUri as prefixr.Delete("/employee/{id}", employee.Delete)
r.Get("/employee/{id}", employee.FindById)
r.Post("/employee", employee.Create)
r.Put("/employee", employee.Update)
})
// Reusable/Common http error handling// See also http.Error// Logs errors via zerolog//// publicMsg is sent to the client (No sensitive/server info)// privateMsg is logged (can contain server info)funcSendPlainTextError(
w http.ResponseWriter,
respCodeint,
publicMsgstring,
privateMsgstring,
causeerror) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.WriteHeader(respCode)
log.Warn().
Err(cause).
Str("publicMessage", publicMsg).
Str("privateMessage", privateMsg).
Msg("Sending error to client")
_, err:=fmt.Fprintln(w, cause)
iferr!=nil {
log.Error().
Caller().
Err(err).
Msg("Failed to send error to client")
}
}