apiutil

package
v4.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeferClose

func DeferClose(c io.Closer, err *error)

DeferClose captures the error returned from closing (if an error occurs). This is designed to be used in a defer statement.

func ErrorResp

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

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

type JSONError

type JSONError struct {
	Err error
}

JSONError lets callers check for just one error type

func (JSONError) Error

func (e JSONError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL