Documentation ¶
Index ¶
- Variables
- func HandleErrors(handlers ...func(err error)) router.MiddlewareFunc
- func Run(requestHttp *http.Request, requestStruct any) error
- func SetTestTx(r *http.Request, tx *sqlx.Tx) *http.Request
- func UseDB(r *http.Request) *sqlx.DB
- func UseTx(r *http.Request) *sqlx.Tx
- func Validate(request *http.Request, keys []string, v any) error
- func WithDB(db *sqlx.DB) router.MiddlewareFunc
- type ErrResponse
- type HTMLResponse
- type HTTPError
- type JSONResponse
- type Message
- type MessageOptions
- type RequestHandler
- type Responder
- type Response
- type ResponseWriter
- type ValidationError
- type Validator
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func HandleErrors ¶
func HandleErrors(handlers ...func(err error)) router.MiddlewareFunc
Types ¶
type ErrResponse ¶
type ErrResponse struct { Error string `json:"error"` Status int `json:"status"` StatusText string `json:"-"` Fields ValidationError `json:"fields,omitempty"` }
type HTMLResponse ¶
type HTMLResponse struct {
Response
}
func NewHTMLResponse ¶
func NewHTMLResponse(data []byte) *HTMLResponse
type HTTPError ¶
type HTTPError struct {
// contains filtered or unexported fields
}
func NewHTTPError ¶
type JSONResponse ¶
type JSONResponse struct {
// contains filtered or unexported fields
}
func NewJSONResponse ¶
func NewJSONResponse(data any) *JSONResponse
func (*JSONResponse) AddHeader ¶
func (r *JSONResponse) AddHeader(key, value string) *JSONResponse
func (*JSONResponse) Respond ¶
func (r *JSONResponse) Respond(w http.ResponseWriter, _ *http.Request) error
func (*JSONResponse) SetStatus ¶
func (r *JSONResponse) SetStatus(status int) *JSONResponse
type Message ¶
type Message struct { Array string `json:"array"` String string `json:"string"` Numeric string `json:"numeric"` }
func (*Message) UnmarshalJSON ¶
type MessageOptions ¶
type RequestHandler ¶
func Handler ¶
func Handler[TRequest, TResponse any](callback func(r *TRequest) (TResponse, error)) RequestHandler[TRequest, TResponse]
Handler is a helper to create http handlers with built in input validation and error handling.
func (RequestHandler[TRequest, TResponse]) ServeHTTP ¶
func (h RequestHandler[TRequest, TResponse]) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func NewResponse ¶
type ResponseWriter ¶
type ResponseWriter struct { http.ResponseWriter Status int }
func (*ResponseWriter) OK ¶
func (w *ResponseWriter) OK() bool
func (*ResponseWriter) WriteHeader ¶
func (w *ResponseWriter) WriteHeader(statusCode int)
type ValidationError ¶
func (ValidationError) AddError ¶
func (e ValidationError) AddError(key string, message string)
func (ValidationError) Error ¶
func (e ValidationError) Error() string
func (ValidationError) HasErrors ¶
func (e ValidationError) HasErrors() bool
func (ValidationError) Merge ¶
func (e ValidationError) Merge(vErr ValidationError)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.