Documentation
¶
Index ¶
- func GetIDParam(r *http.Request) (int32, error)
- func NewError(err error, statusCode int) error
- func NewErrorFromMessage(message string, statusCode int) error
- func NewErrorFromStatusCode(statusCode int) error
- func NewErrorWithFields(err error, statusCode int, fields []FieldError) error
- func Respond(w http.ResponseWriter, val any, statusCode int)
- func Respond500(w http.ResponseWriter)
- func RespondError(w http.ResponseWriter, respErr error)
- type Decoder
- type Error
- type ErrorResponse
- type FieldError
- type Sanitizable
- type Validatable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewErrorFromMessage ¶
NewErrorFromMessage creates error with status code from message
func NewErrorFromStatusCode ¶
NewErrorFromStatusCode creates error from status code
func NewErrorWithFields ¶
func NewErrorWithFields(err error, statusCode int, fields []FieldError) error
NewErrorWithFields creates error with status code and error fields
func Respond ¶
func Respond(w http.ResponseWriter, val any, statusCode int)
Respond marshals a value to JSON and writes it to response
func Respond500 ¶
func Respond500(w http.ResponseWriter)
Respond500 returns InternalServerError to client
func RespondError ¶
func RespondError(w http.ResponseWriter, respErr error)
RespondError handles outgoing errors by marshaling an error response. if error is not of type Error, then err is ignored. if no err is provided, InternalServerError returns to client
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes JSON request
func NewDecoder ¶
NewDecoder creates new decoder
type Error ¶
type Error struct {
Err error
StatusCode int
Fields []FieldError
}
Error contains information about web error
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
Fields []FieldError `json:"fields,omitempty"`
}
ErrorResponse represents response in case of a web error
type FieldError ¶
FieldError represents error in a struct field
type Sanitizable ¶
type Sanitizable interface {
Sanitize()
}
Sanitizable interface that request structs must implement
type Validatable ¶
type Validatable interface {
ValidateWith(v *validation.Validator) (bool, []FieldError)
}
Validatable interface that request structs must implement