muxhandler

package
v0.0.0-...-4827418 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JsonResponse

func JsonResponse(w http.ResponseWriter, status int, obj interface{}) error

func NotFound

func NotFound() http.Handler

func Respond

func Respond(w http.ResponseWriter, r *http.Request, statusCode int, response interface{})

Respond is used to return data to the client with a custom http code The returned content-type will respect the Accept header for application/json, application/cbor and application/xml (and application/html and text/html if enabled with SetHTMLTemplatePaths).

func RespondError

func RespondError(w http.ResponseWriter, r *http.Request, statusCode int, detail ...interface{})

RespondError is used to return errors to the client The returned content-type will respect the Accept header for application/json, application/cbor and application/xml (and application/html and text/html if enabled with SetHTMLTemplatePaths). Be careful in here not to recurse (by calling RespondError() again) when there is an error. For the detail parameter, only error, string and RespondErrorDetail types are useful.

func RespondOk

func RespondOk(w http.ResponseWriter, r *http.Request, response interface{})

RespondOk is used to return data to the client with a 200 http code The returned content-type will respect the Accept header for application/json, application/cbor and application/xml (and application/html and text/html if enabled with SetHTMLTemplatePaths).

Types

type JsonRes

type JsonRes map[string]interface{}

type RespondErrorDetail

type RespondErrorDetail string

RespondErrorDetail allows a RespondError detail parameter to end up in the Details array

type ResponseError

type ResponseError struct {
	StatusCode    int      `json:"status_code"`
	Message       string   `json:"message"`
	Documentation string   `json:"documentation"`
	Details       []string `json:"details,omitempty"`
}

ResponseError structure holds standard fields for errors. Public so that when two of our own applications communicate; one can parse the error received from the other.

Jump to

Keyboard shortcuts

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