utils

package
v0.0.0-...-71e40f4 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: LGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSONContentType        = "application/json; charset=utf-8"
	OctetStreamContentType = "application/octet-stream"
)

content types

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(cause error) error

BadRequest convenience method to create http bad request error.

func Forbidden

func Forbidden(cause error) error

Forbidden convenience method to create http forbidden error.

func HTTPError

func HTTPError(cause error, status int) error

HTTPError create an error with http status code.

func ParseJSON

func ParseJSON(r io.Reader, v interface{}) error

ParseJSON parse a JSON object using strict mode.

func WrapHandlerFunc

func WrapHandlerFunc(f HandlerFunc) http.HandlerFunc

WrapHandlerFunc convert HandlerFunc to http.HandlerFunc.

func WriteJSON

func WriteJSON(w http.ResponseWriter, obj interface{}) error

WriteJSON reponse a object in JSON enconding.

Types

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) error

HandlerFunc like http.HandlerFunc, bu it returns an error. If the returned error is httpError type, httpError.status will be responded, otherwise http.StatusInternalServerError responded.

type M

type M map[string]interface{}

M shortcut for type map[string]interface{}.

Jump to

Keyboard shortcuts

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