httprouter

package
v1.0.47 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: Apache-2.0 Imports: 16 Imported by: 6

Documentation

Index

Constants

View Source
const (
	ContentTypeJSON           = "application/json"
	ContentTypeText           = "text/plain"
	ContentTypeMultipartForm  = "multipart/form-data"
	ContentTypeUrlEncodedForm = "application/x-www-form-urlencoded"
)
View Source
const (
	PathSeparator = string(os.PathSeparator)
)

Variables

This section is empty.

Functions

func New

func New() *router

func RequestBody

func RequestBody(req *http.Request, v interface{}) error

RequestBody returns the body of a request as a struct

func RequestBodyForm

func RequestBodyForm(req *http.Request, params map[string]string, v interface{}) error

RequestBodyForm returns the body of a request as a struct where the request is of type multipart/form-data

func RequestBodyJSON

func RequestBodyJSON(req *http.Request, v interface{}) error

RequestBodyJSON returns the body of a request as a struct where the request is of type application/json

func RequestBodyPost

func RequestBodyPost(req *http.Request, v interface{}) error

RequestBodyPost returns the body of a request as a struct where the request is of type application/x-www-form-urlencoded

func RequestParams

func RequestParams(req *http.Request) []string

RequestParams returns the parameters encoded within the reqular expression

func RequestQuery

func RequestQuery(req *http.Request, v interface{}) error

RequestQuery returns the query string of a request as a struct

func ServeError

func ServeError(w http.ResponseWriter, code int, reason ...string) error

ServeError is a utility function to serve a JSON error notice

func ServeJSON

func ServeJSON(w http.ResponseWriter, v interface{}, code, indent uint) error

ServeJSON is a utility function to serve an arbitary object as JSON

func ServeText

func ServeText(w http.ResponseWriter, v string, code int)

ServeText is a utility function to serve plaintext

Types

type ErrorResponse

type ErrorResponse struct {
	Code   int    `json:"code"`
	Reason string `json:"reason,omitempty"`
}

Jump to

Keyboard shortcuts

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