Documentation ¶
Index ¶
- Constants
- Variables
- func Bind(r BindableRequest, i interface{}) error
- func BindBody(r BindableRequest, i interface{}) error
- func BindHeaders(r BindableRequest, i interface{}) error
- func BindHttp(r *http.Request, i interface{}) error
- func BindHttpBody(r *http.Request, i interface{}) error
- func BindHttpHeaders(r *http.Request, i interface{}) error
- func BindHttpPathParms(r *http.Request, i interface{}) error
- func BindHttpQueryParams(r *http.Request, i interface{}) error
- func BindPathParams(r BindableRequest, i interface{}) error
- func BindQueryParams(r BindableRequest, i interface{}) error
- type BindFunc
- type BindUnmarshaler
- type BindableRequest
- type Binder
- type DefaultBinder
- func (b *DefaultBinder) Bind(r BindableRequest, i interface{}) (err error)
- func (b *DefaultBinder) BindBody(r BindableRequest, i interface{}) (err error)
- func (b *DefaultBinder) BindHeaders(r BindableRequest, i interface{}) error
- func (b *DefaultBinder) BindPathParams(r BindableRequest, i interface{}) error
- func (b *DefaultBinder) BindQueryParams(r BindableRequest, i interface{}) error
- func (b *DefaultBinder) GetHeaders(r BindableRequest) map[string][]string
- func (b *DefaultBinder) GetPathParams(r BindableRequest) map[string][]string
- func (b *DefaultBinder) GetQueryParams(r BindableRequest) map[string][]string
- type DefaultJSONSerializer
- type DefaultXMLSerializer
- type HttpBindableRequest
- func (r HttpBindableRequest) GetBody() io.Reader
- func (r HttpBindableRequest) GetContentLength() int64
- func (r HttpBindableRequest) GetContentType() string
- func (r HttpBindableRequest) GetForm() (url.Values, error)
- func (r HttpBindableRequest) GetHeaders() url.Values
- func (r HttpBindableRequest) GetMultipartForm(maxBodySize int64) (*multipart.Form, error)
- func (r HttpBindableRequest) GetPathPattern() string
- func (r HttpBindableRequest) GetPathValue(key string) string
- func (r HttpBindableRequest) GetQuery() url.Values
- type HttpBinder
- func (b *HttpBinder) Bind(r *http.Request, i interface{}) error
- func (b *HttpBinder) BindBody(r *http.Request, i interface{}) error
- func (b *HttpBinder) BindHeaders(r *http.Request, i interface{}) error
- func (b *HttpBinder) BindPathParams(r *http.Request, i interface{}) error
- func (b *HttpBinder) BindQueryParams(r *http.Request, i interface{}) error
- type JSONSerializer
- type XMLSerializer
Constants ¶
const ( CONNECT = http.MethodConnect DELETE = http.MethodDelete GET = http.MethodGet HEAD = http.MethodHead OPTIONS = http.MethodOptions PATCH = http.MethodPatch POST = http.MethodPost // PROPFIND = "PROPFIND" PUT = http.MethodPut TRACE = http.MethodTrace )
HTTP methods NOTE: Deprecated, please use the stdlib constants directly instead.
const ( // MIMEApplicationJSON JavaScript Object Notation (JSON) https://www.rfc-editor.org/rfc/rfc8259 MIMEApplicationJSON = "application/json" // Deprecated: Please use MIMEApplicationJSON instead. JSON should be encoded using UTF-8 by default. // No "charset" parameter is defined for this registration. // Adding one really has no effect on compliant recipients. // See RFC 8259, section 8.1. https://datatracker.ietf.org/doc/html/rfc8259#section-8.1 MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8 MIMEApplicationJavaScript = "application/javascript" MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8 MIMEApplicationXML = "application/xml" MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8 MIMETextXML = "text/xml" MIMETextXMLCharsetUTF8 = MIMETextXML + "; " + charsetUTF8 MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEApplicationProtobuf = "application/protobuf" MIMEApplicationMsgpack = "application/msgpack" MIMETextHTML = "text/html" MIMETextHTMLCharsetUTF8 = MIMETextHTML + "; " + charsetUTF8 MIMETextPlain = "text/plain" MIMETextPlainCharsetUTF8 = MIMETextPlain + "; " + charsetUTF8 MIMEMultipartForm = "multipart/form-data" MIMEOctetStream = "application/octet-stream" )
MIME types
const ( // PROPFIND Method can be used on collection and property resources. PROPFIND = "PROPFIND" // REPORT Method can be used to get information about a resource, see rfc 3253 REPORT = "REPORT" // RouteNotFound is special method type for routes handling "route not found" (404) cases RouteNotFound = "echo_route_not_found" )
const ( HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" // HeaderAllow is the name of the "Allow" header field used to list the set of methods // advertised as supported by the target resource. Returning an Allow header is mandatory // for status 405 (method not found) and useful for the OPTIONS method in responses. // See RFC 7231: https://datatracker.ietf.org/doc/html/rfc7231#section-7.4.1 HeaderAllow = "Allow" HeaderAuthorization = "Authorization" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-Encoding" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderCookie = "Cookie" HeaderSetCookie = "Set-Cookie" HeaderIfModifiedSince = "If-Modified-Since" HeaderLastModified = "Last-Modified" HeaderLocation = "Location" HeaderRetryAfter = "Retry-After" HeaderUpgrade = "Upgrade" HeaderVary = "Vary" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXForwardedProtocol = "X-Forwarded-Protocol" HeaderXForwardedSsl = "X-Forwarded-Ssl" HeaderXUrlScheme = "X-Url-Scheme" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXRealIP = "X-Real-Ip" HeaderXRequestID = "X-Request-Id" HeaderXCorrelationID = "X-Correlation-Id" HeaderXRequestedWith = "X-Requested-With" HeaderServer = "Server" HeaderOrigin = "Origin" HeaderCacheControl = "Cache-Control" HeaderConnection = "Connection" // Access control HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" // Security HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXXSSProtection = "X-XSS-Protection" HeaderXFrameOptions = "X-Frame-Options" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only" HeaderXCSRFToken = "X-CSRF-Token" HeaderReferrerPolicy = "Referrer-Policy" )
Headers
Variables ¶
var ArrayMatcherRegexp = regexp.MustCompile(`\[([0-9]+)\]`) // matches [0] to use in indexed arrays
var ArrayNotationRegexp = regexp.MustCompile(`\[([a-zA-Z0-9\-\_\.]+)\]`) // matches [id] to use in deep objects
var DefaultBodySize = int64(32 << 20) // 32 MB
var DefaultDeepObjectSeparator = "." // default separator for deep fields
var DefaultFormTagName = "form" // default tag name for form
var DefaultHeaderTagName = "header" // default tag name for header
var DefaultParamTagName = "param" // default tag name for param
var DefaultQueryTagName = "query" // default tag name for query
var MapMatcherRegexp = regexp.MustCompile(`\[([a-zA-Z0-9\-\_\.]+)\]`) // matches [key] to use in maps and deep objects
var MaxArraySize = 1000 // max size of array
var PathMatcherRegexp = regexp.MustCompile(`\{([^}]+)\}`) // matches {id} to use in path parameters
Functions ¶
func Bind ¶ added in v0.0.2
func Bind(r BindableRequest, i interface{}) error
func BindBody ¶ added in v0.0.2
func BindBody(r BindableRequest, i interface{}) error
func BindHeaders ¶ added in v0.0.2
func BindHeaders(r BindableRequest, i interface{}) error
func BindHttpBody ¶ added in v0.0.2
BindHttpBody binds an http.Request body to a struct or map.
func BindHttpHeaders ¶ added in v0.0.2
func BindHttpPathParms ¶ added in v0.0.2
func BindHttpQueryParams ¶ added in v0.0.2
func BindPathParams ¶ added in v0.0.2
func BindPathParams(r BindableRequest, i interface{}) error
func BindQueryParams ¶ added in v0.0.2
func BindQueryParams(r BindableRequest, i interface{}) error
Types ¶
type BindFunc ¶ added in v0.0.2
type BindFunc func(r BindableRequest, i interface{}) error
type BindUnmarshaler ¶
type BindUnmarshaler interface { // UnmarshalParam decodes and assigns a value from an form or query param. UnmarshalParam(param string) error }
BindUnmarshaler is the interface used to wrap the UnmarshalParam method. Types that don't implement this, but do implement encoding.TextUnmarshaler will use that interface instead.
type BindableRequest ¶ added in v0.0.2
type BindableRequest interface { GetBody() io.Reader GetPathPattern() string GetPathValue(string) string GetQuery() url.Values GetHeaders() url.Values GetContentLength() int64 GetContentType() string GetForm() (url.Values, error) GetMultipartForm(maxBodySize int64) (*multipart.Form, error) }
BindableRequest is the interface that wraps the basic methods required for a request to be bindable.
This enables non-HTTP request types to be bindable.
type Binder ¶
type Binder interface { Bind(r BindableRequest, i interface{}) error BindBody(r BindableRequest, i interface{}) error BindPathParams(r BindableRequest, i interface{}) error BindQueryParams(r BindableRequest, i interface{}) error BindHeaders(r BindableRequest, i interface{}) error }
var DefaultBinderInstance Binder
type DefaultBinder ¶
type DefaultBinder struct { JSONSerializer JSONSerializer XMLSerializer XMLSerializer PathMatcher *regexp.Regexp ArrayMatcher *regexp.Regexp MapMatcher *regexp.Regexp ArrayNotationMatcher *regexp.Regexp DeepObjectSeparator string MaxBodySize int64 MaxArraySize int HeaderTagName string FormTagName string QueryTagName string ParamTagName string BindOrder []BindFunc }
DefaultBinder is the default implementation of the `Binder` interface.
func NewBinder ¶
func NewBinder() *DefaultBinder
func (*DefaultBinder) Bind ¶
func (b *DefaultBinder) Bind(r BindableRequest, i interface{}) (err error)
Bind implements the `Binder#Bind` function. Binding is done in following order: 1) path params; 2) query params; 3) request body. Each step COULD override previous step binded values. For single source binding use their own methods BindBody, BindQueryParams, BindPathParams.
func (*DefaultBinder) BindBody ¶
func (b *DefaultBinder) BindBody(r BindableRequest, i interface{}) (err error)
BindBody binds request body contents to bindable object NB: then binding forms take note that this implementation uses standard library form parsing which parses form data from BOTH URL and BODY if content type is not MIMEMultipartForm See non-MIMEMultipartForm: https://golang.org/pkg/net/http/#Request.ParseForm See MIMEMultipartForm: https://golang.org/pkg/net/http/#Request.ParseMultipartForm
func (*DefaultBinder) BindHeaders ¶
func (b *DefaultBinder) BindHeaders(r BindableRequest, i interface{}) error
BindHeaders binds HTTP headers to a bindable object
func (*DefaultBinder) BindPathParams ¶
func (b *DefaultBinder) BindPathParams(r BindableRequest, i interface{}) error
BindPathParams binds path params to bindable object
func (*DefaultBinder) BindQueryParams ¶
func (b *DefaultBinder) BindQueryParams(r BindableRequest, i interface{}) error
BindQueryParams binds query params to bindable object
func (*DefaultBinder) GetHeaders ¶ added in v0.0.2
func (b *DefaultBinder) GetHeaders(r BindableRequest) map[string][]string
func (*DefaultBinder) GetPathParams ¶ added in v0.0.2
func (b *DefaultBinder) GetPathParams(r BindableRequest) map[string][]string
func (*DefaultBinder) GetQueryParams ¶ added in v0.0.2
func (b *DefaultBinder) GetQueryParams(r BindableRequest) map[string][]string
type DefaultJSONSerializer ¶
type DefaultJSONSerializer struct{}
func (DefaultJSONSerializer) Deserialize ¶
func (DefaultJSONSerializer) Deserialize(r BindableRequest, i interface{}) error
type DefaultXMLSerializer ¶
type DefaultXMLSerializer struct{}
func (DefaultXMLSerializer) Deserialize ¶
func (DefaultXMLSerializer) Deserialize(r BindableRequest, i interface{}) error
type HttpBindableRequest ¶ added in v0.0.2
func NewHttpBindableRequest ¶ added in v0.0.2
func NewHttpBindableRequest(r *http.Request) HttpBindableRequest
func (HttpBindableRequest) GetBody ¶ added in v0.0.2
func (r HttpBindableRequest) GetBody() io.Reader
func (HttpBindableRequest) GetContentLength ¶ added in v0.0.2
func (r HttpBindableRequest) GetContentLength() int64
func (HttpBindableRequest) GetContentType ¶ added in v0.0.2
func (r HttpBindableRequest) GetContentType() string
func (HttpBindableRequest) GetForm ¶ added in v0.0.2
func (r HttpBindableRequest) GetForm() (url.Values, error)
func (HttpBindableRequest) GetHeaders ¶ added in v0.0.2
func (r HttpBindableRequest) GetHeaders() url.Values
func (HttpBindableRequest) GetMultipartForm ¶ added in v0.0.2
func (r HttpBindableRequest) GetMultipartForm(maxBodySize int64) (*multipart.Form, error)
func (HttpBindableRequest) GetPathPattern ¶ added in v0.0.2
func (r HttpBindableRequest) GetPathPattern() string
func (HttpBindableRequest) GetPathValue ¶ added in v0.0.2
func (r HttpBindableRequest) GetPathValue(key string) string
func (HttpBindableRequest) GetQuery ¶ added in v0.0.2
func (r HttpBindableRequest) GetQuery() url.Values
type HttpBinder ¶ added in v0.0.2
type HttpBinder struct {
Binder
}
var DefaultHttpBinder *HttpBinder
func GetHttpBinder ¶ added in v0.0.2
func GetHttpBinder() *HttpBinder
func NewHttpBinder ¶ added in v0.0.2
func NewHttpBinder() *HttpBinder
func (*HttpBinder) Bind ¶ added in v0.0.2
func (b *HttpBinder) Bind(r *http.Request, i interface{}) error
func (*HttpBinder) BindBody ¶ added in v0.0.2
func (b *HttpBinder) BindBody(r *http.Request, i interface{}) error
func (*HttpBinder) BindHeaders ¶ added in v0.0.2
func (b *HttpBinder) BindHeaders(r *http.Request, i interface{}) error
func (*HttpBinder) BindPathParams ¶ added in v0.0.2
func (b *HttpBinder) BindPathParams(r *http.Request, i interface{}) error
func (*HttpBinder) BindQueryParams ¶ added in v0.0.2
func (b *HttpBinder) BindQueryParams(r *http.Request, i interface{}) error
type JSONSerializer ¶
type JSONSerializer interface { // Serialize(c context.Context, i interface{}, indent string) error Deserialize(r BindableRequest, i interface{}) error }
JSONSerializer is the interface that encodes and decodes JSON to and from interfaces.
type XMLSerializer ¶
type XMLSerializer interface {
Deserialize(r BindableRequest, i interface{}) error
}