res: go.bobheadxi.dev/res Index | Files | Directories

package res

import "go.bobheadxi.dev/res"

Index

Package Files

error.go message.go res.go

func R Uses

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

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

func Unmarshal Uses

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 Uses

type ErrResponse struct {
    *base.Response
}

ErrResponse is the template for a typical HTTP response for errors

func Err Uses

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

Err is a basic error response constructor

func ErrBadRequest Uses

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

ErrBadRequest is a shortcut for bad requests

func ErrForbidden Uses

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

ErrForbidden is a shortcut for forbidden requests

func ErrInternalServer Uses

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 Uses

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

ErrNotFound is a shortcut for forbidden requests

func ErrUnauthorized Uses

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

ErrUnauthorized is a shortcut for unauthorized requests

type KV Uses

type KV struct {
    Key   string
    Value interface{}
}

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

type M Uses

type M map[string]interface{}

M is an alias for a map

type MsgResponse Uses

type MsgResponse struct {
    *base.Response
}

MsgResponse is the template for a typical HTTP response for messages

func Msg Uses

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

Msg is a shortcut for non-error statuses

func MsgOK Uses

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

MsgOK is a shortcut for an ok-status response

Directories

PathSynopsis
base

Package res imports 7 packages (graph) and is imported by 2 packages. Updated 2019-08-14. Refresh now. Tools for package owners.