Back to

Package res

Latest Go to latest

The latest major version is .

Published: May 6, 2019 | License: MIT | Module:


func R

func R(w http.ResponseWriter, r *http.Request, v render.Renderer)

R is an alias for go-chi/render.Render

func Unmarshal

func Unmarshal(r io.Reader, kvs ...KV) (*base.Response, error)

Unmarshal reads the response and unmarshalls the BaseResponse as well any requested key-value pairs. For example:

var prop = map[string]string
api.Unmarshal(resp.Body, api.KV{Key: "prop", Value: &prop})

Values provided in KV.Value MUST be explicit pointers, even if the value is a pointer type, ie maps and slices.

type ErrResponse

type ErrResponse struct {

ErrResponse is the template for a typical HTTP response for errors

func Err

func Err(message string, code int, kvs ...interface{}) *ErrResponse

Err is a basic error response constructor

func ErrBadRequest

func ErrBadRequest(message string, kvs ...interface{}) *ErrResponse

ErrBadRequest is a shortcut for bad requests

func ErrForbidden

func ErrForbidden(message string, kvs ...interface{}) *ErrResponse

ErrForbidden is a shortcut for forbidden requests

func ErrInternalServer

func ErrInternalServer(message string, err error, kvs ...interface{}) *ErrResponse

ErrInternalServer is a shortcut for internal server errors. It should be accompanied by an actual error.

func ErrNotFound

func ErrNotFound(message string, kvs ...interface{}) *ErrResponse

ErrNotFound is a shortcut for forbidden requests

func ErrUnauthorized

func ErrUnauthorized(message string, kvs ...interface{}) *ErrResponse

ErrUnauthorized is a shortcut for unauthorized requests

type KV

type KV struct {
	Key   string
	Value interface{}

KV is used for defining specific values to be unmarshalled from BaseResponse data

type M

type M map[string]interface{}

M is an alias for a map

type MsgResponse

type MsgResponse struct {

MsgResponse is the template for a typical HTTP response for messages

func Msg

func Msg(message string, code int, kvs ...interface{}) *MsgResponse

Msg is a shortcut for non-error statuses

func MsgOK

func MsgOK(message string, kvs ...interface{}) *MsgResponse

MsgOK is a shortcut for an ok-status response

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier