Documentation ¶
Index ¶
- func DeferClose(c io.Closer, err *error)
- func ErrorResp(rd *render.Render, w http.ResponseWriter, err error)
- func ReadJSON(r io.ReadCloser, data interface{}) error
- func ReadJSONRespondError(rd *render.Render, w http.ResponseWriter, body io.ReadCloser, data interface{}) error
- type FieldError
- type JSONError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeferClose ¶
DeferClose captures the error returned from closing (if an error occurs). This is designed to be used in a defer statement.
func ErrorResp ¶ added in v3.1.0
func ErrorResp(rd *render.Render, w http.ResponseWriter, err error)
ErrorResp Respond to the client about the given error, integrating with errcode.ErrorCode.
Important: if the `err` is just an error and not an errcode.ErrorCode (given by errors.Cause), then by default an error is assumed to be a 500 Internal Error.
If the error is nil, this also responds with a 500 and logs at the error level.
func ReadJSON ¶
func ReadJSON(r io.ReadCloser, data interface{}) error
ReadJSON reads a JSON data from r and then closes it. An error due to invalid json will be returned as a JSONError
func ReadJSONRespondError ¶ added in v3.1.0
func ReadJSONRespondError(rd *render.Render, w http.ResponseWriter, body io.ReadCloser, data interface{}) error
ReadJSONRespondError writes json into data. On error respond with a 400 Bad Request
Types ¶
type FieldError ¶
type FieldError struct {
// contains filtered or unexported fields
}
FieldError connects an error to a particular field
func ParseUint64VarsField ¶
func ParseUint64VarsField(vars map[string]string, varName string) (uint64, *FieldError)
ParseUint64VarsField connects strconv.ParseUint with request variables It hardcodes the base to 10 and bitsize to 64 Any error returned will connect the requested field to the error via FieldError