Documentation
¶
Overview ¶
Package chiserver provides a production-ready Chi HTTP server with:
- Chi middleware: RequestID, RealIP, Recoverer
- CORS headers
- JSON error responses via RespondError
- /health endpoint
- BindAndValidate for JSON + validator tags
Usage:
srv := chiserver.New(chiserver.Config{Port: 8080})
r := srv.Router()
r.Mount("/api/v1", userHandler.Routes())
if err := srv.Run(); err != nil { ... }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindAndValidate ¶
BindAndValidate decodes JSON from the body and runs struct tag validation. On failure it writes 400 JSON and returns the error.
func RespondError ¶
func RespondError(w http.ResponseWriter, err error)
RespondError writes a JSON error body with status from apperrors.HTTPStatus.
Types ¶
Click to show internal directories.
Click to hide internal directories.