Documentation ¶
Index ¶
- Constants
- Variables
- func NewBindingError(sourceParam string, values []string, message string, err error) error
- type BindUnmarshaler
- type BindingError
- type DefaultRequestBinder
- type HTTPError
- type HTTPErrorHandlerFunc
- type HandlerFunc
- type Request
- func (r *Request) Bind(v any) error
- func (r *Request) FormFile(name string) (*multipart.FileHeader, error)
- func (r *Request) FormParams() (url.Values, error)
- func (r *Request) GetValue(key any) any
- func (r *Request) IsTLS() bool
- func (r *Request) IsWebSocket() bool
- func (r *Request) MultipartForm() (*multipart.Form, error)
- func (r *Request) QueryParam(name string) string
- func (r *Request) QueryParams() url.Values
- func (r *Request) QueryString() string
- func (r *Request) Scheme() string
- func (r *Request) SetValue(key, val any)
- type Responder
- func (r *Responder) After(fn func())
- func (r *Responder) Before(fn func())
- func (r *Responder) Blob(contentType string, b []byte) error
- func (r *Responder) Flush()
- func (r *Responder) HTML(html string) error
- func (r *Responder) Header() http.Header
- func (r *Responder) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (r *Responder) JSON(i any, indent string) error
- func (r *Responder) NoContent() error
- func (r *Responder) Redirect(url string) error
- func (r *Responder) SetCookie(cookie *http.Cookie) *Responder
- func (r *Responder) Status(code int) *Responder
- func (r *Responder) Stream(contentType string, reader io.Reader) error
- func (r *Responder) String(s string) error
- func (r *Responder) Template(tpl *template.Template, name string, data any) error
- func (r *Responder) Write(b []byte) (n int, err error)
- func (r *Responder) WriteHeader(code int)
- func (r *Responder) XML(i any, indent string) error
- type ValueBinder
- func (b *ValueBinder) BindError() error
- func (b *ValueBinder) BindErrors() []error
- func (b *ValueBinder) BindUnmarshaler(sourceParam string, dest BindUnmarshaler) *ValueBinder
- func (b *ValueBinder) BindWithDelimiter(sourceParam string, dest any, delimiter string) *ValueBinder
- func (b *ValueBinder) Bool(sourceParam string, dest *bool) *ValueBinder
- func (b *ValueBinder) Bools(sourceParam string, dest *[]bool) *ValueBinder
- func (b *ValueBinder) Byte(sourceParam string, dest *byte) *ValueBinder
- func (b *ValueBinder) CustomFunc(sourceParam string, customFunc func(values []string) []error) *ValueBinder
- func (b *ValueBinder) Duration(sourceParam string, dest *time.Duration) *ValueBinder
- func (b *ValueBinder) Durations(sourceParam string, dest *[]time.Duration) *ValueBinder
- func (b *ValueBinder) FailFast(value bool) *ValueBinder
- func (b *ValueBinder) Float32(sourceParam string, dest *float32) *ValueBinder
- func (b *ValueBinder) Float32s(sourceParam string, dest *[]float32) *ValueBinder
- func (b *ValueBinder) Float64(sourceParam string, dest *float64) *ValueBinder
- func (b *ValueBinder) Float64s(sourceParam string, dest *[]float64) *ValueBinder
- func (b *ValueBinder) Int(sourceParam string, dest *int) *ValueBinder
- func (b *ValueBinder) Int16(sourceParam string, dest *int16) *ValueBinder
- func (b *ValueBinder) Int16s(sourceParam string, dest *[]int16) *ValueBinder
- func (b *ValueBinder) Int32(sourceParam string, dest *int32) *ValueBinder
- func (b *ValueBinder) Int32s(sourceParam string, dest *[]int32) *ValueBinder
- func (b *ValueBinder) Int64(sourceParam string, dest *int64) *ValueBinder
- func (b *ValueBinder) Int64s(sourceParam string, dest *[]int64) *ValueBinder
- func (b *ValueBinder) Int8(sourceParam string, dest *int8) *ValueBinder
- func (b *ValueBinder) Int8s(sourceParam string, dest *[]int8) *ValueBinder
- func (b *ValueBinder) Ints(sourceParam string, dest *[]int) *ValueBinder
- func (b *ValueBinder) MustBindUnmarshaler(sourceParam string, dest BindUnmarshaler) *ValueBinder
- func (b *ValueBinder) MustBindWithDelimiter(sourceParam string, dest any, delimiter string) *ValueBinder
- func (b *ValueBinder) MustBool(sourceParam string, dest *bool) *ValueBinder
- func (b *ValueBinder) MustBools(sourceParam string, dest *[]bool) *ValueBinder
- func (b *ValueBinder) MustByte(sourceParam string, dest *byte) *ValueBinder
- func (b *ValueBinder) MustCustomFunc(sourceParam string, customFunc func(values []string) []error) *ValueBinder
- func (b *ValueBinder) MustDuration(sourceParam string, dest *time.Duration) *ValueBinder
- func (b *ValueBinder) MustDurations(sourceParam string, dest *[]time.Duration) *ValueBinder
- func (b *ValueBinder) MustFloat32(sourceParam string, dest *float32) *ValueBinder
- func (b *ValueBinder) MustFloat32s(sourceParam string, dest *[]float32) *ValueBinder
- func (b *ValueBinder) MustFloat64(sourceParam string, dest *float64) *ValueBinder
- func (b *ValueBinder) MustFloat64s(sourceParam string, dest *[]float64) *ValueBinder
- func (b *ValueBinder) MustInt(sourceParam string, dest *int) *ValueBinder
- func (b *ValueBinder) MustInt16(sourceParam string, dest *int16) *ValueBinder
- func (b *ValueBinder) MustInt16s(sourceParam string, dest *[]int16) *ValueBinder
- func (b *ValueBinder) MustInt32(sourceParam string, dest *int32) *ValueBinder
- func (b *ValueBinder) MustInt32s(sourceParam string, dest *[]int32) *ValueBinder
- func (b *ValueBinder) MustInt64(sourceParam string, dest *int64) *ValueBinder
- func (b *ValueBinder) MustInt64s(sourceParam string, dest *[]int64) *ValueBinder
- func (b *ValueBinder) MustInt8(sourceParam string, dest *int8) *ValueBinder
- func (b *ValueBinder) MustInt8s(sourceParam string, dest *[]int8) *ValueBinder
- func (b *ValueBinder) MustInts(sourceParam string, dest *[]int) *ValueBinder
- func (b *ValueBinder) MustString(sourceParam string, dest *string) *ValueBinder
- func (b *ValueBinder) MustStrings(sourceParam string, dest *[]string) *ValueBinder
- func (b *ValueBinder) MustTime(sourceParam string, dest *time.Time, layout string) *ValueBinder
- func (b *ValueBinder) MustTimes(sourceParam string, dest *[]time.Time, layout string) *ValueBinder
- func (b *ValueBinder) MustUint(sourceParam string, dest *uint) *ValueBinder
- func (b *ValueBinder) MustUint16(sourceParam string, dest *uint16) *ValueBinder
- func (b *ValueBinder) MustUint16s(sourceParam string, dest *[]uint16) *ValueBinder
- func (b *ValueBinder) MustUint32(sourceParam string, dest *uint32) *ValueBinder
- func (b *ValueBinder) MustUint32s(sourceParam string, dest *[]uint32) *ValueBinder
- func (b *ValueBinder) MustUint64(sourceParam string, dest *uint64) *ValueBinder
- func (b *ValueBinder) MustUint64s(sourceParam string, dest *[]uint64) *ValueBinder
- func (b *ValueBinder) MustUint8(sourceParam string, dest *uint8) *ValueBinder
- func (b *ValueBinder) MustUint8s(sourceParam string, dest *[]uint8) *ValueBinder
- func (b *ValueBinder) MustUints(sourceParam string, dest *[]uint) *ValueBinder
- func (b *ValueBinder) MustUnixTime(sourceParam string, dest *time.Time) *ValueBinder
- func (b *ValueBinder) MustUnixTimeNano(sourceParam string, dest *time.Time) *ValueBinder
- func (b *ValueBinder) String(sourceParam string, dest *string) *ValueBinder
- func (b *ValueBinder) Strings(sourceParam string, dest *[]string) *ValueBinder
- func (b *ValueBinder) Time(sourceParam string, dest *time.Time, layout string) *ValueBinder
- func (b *ValueBinder) Times(sourceParam string, dest *[]time.Time, layout string) *ValueBinder
- func (b *ValueBinder) Uint(sourceParam string, dest *uint) *ValueBinder
- func (b *ValueBinder) Uint16(sourceParam string, dest *uint16) *ValueBinder
- func (b *ValueBinder) Uint16s(sourceParam string, dest *[]uint16) *ValueBinder
- func (b *ValueBinder) Uint32(sourceParam string, dest *uint32) *ValueBinder
- func (b *ValueBinder) Uint32s(sourceParam string, dest *[]uint32) *ValueBinder
- func (b *ValueBinder) Uint64(sourceParam string, dest *uint64) *ValueBinder
- func (b *ValueBinder) Uint64s(sourceParam string, dest *[]uint64) *ValueBinder
- func (b *ValueBinder) Uint8(sourceParam string, dest *uint8) *ValueBinder
- func (b *ValueBinder) Uint8s(sourceParam string, dest *[]uint8) *ValueBinder
- func (b *ValueBinder) Uints(sourceParam string, dest *[]uint) *ValueBinder
- func (b *ValueBinder) UnixTime(sourceParam string, dest *time.Time) *ValueBinder
- func (b *ValueBinder) UnixTimeNano(sourceParam string, dest *time.Time) *ValueBinder
Constants ¶
const ( MIMEApplicationJSON = "application/json" 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 ( HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" 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" 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" 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 ( ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType) ErrNotFound = NewHTTPError(http.StatusNotFound) ErrForbidden = NewHTTPError(http.StatusForbidden) ErrMethodNotAllowed = NewHTTPError(http.StatusMethodNotAllowed) ErrStatusRequestEntityTooLarge = NewHTTPError(http.StatusRequestEntityTooLarge) ErrTooManyRequests = NewHTTPError(http.StatusTooManyRequests) ErrBadRequest = NewHTTPError(http.StatusBadRequest) ErrBadGateway = NewHTTPError(http.StatusBadGateway) ErrInternalServerError = NewHTTPError(http.StatusInternalServerError) ErrRequestTimeout = NewHTTPError(http.StatusRequestTimeout) )
HTTP Errors
var ( // Logger is the global logger used to log library-specific internal errors. // Set this global variable to your preferred logger. Defaults to stdlib log. Logger logger = log.New(os.Stderr, "httpx: ", log.LstdFlags|log.Lmsgprefix) // HTTPErrorHandler is used to handle all HTTP errors returned by every HTTP handler. // Set this global variable to customise the behaviour. HTTPErrorHandler HTTPErrorHandlerFunc = HandleHTTPError(false) )
var RequestBinder interface { Bind(req *Request, v any) error } = new(DefaultRequestBinder)
RequestBinder is used to bind request body data to objects. Set this global variable to your preferred binder once before calling any Request.Bind. The default DefaultRequestBinder binds data according to the "Content-Type" header.
Functions ¶
Types ¶
type BindUnmarshaler ¶ added in v0.2.0
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 BindingError ¶ added in v0.2.0
type BindingError struct { *HTTPError // Field is the field name where value binding failed. Field string `json:"field"` // Values of parameter that failed to bind. Values []string `json:"-"` }
BindingError represents an error that occurred while binding request data.
func (*BindingError) Error ¶ added in v0.2.0
func (be *BindingError) Error() string
Error returns error message.
type DefaultRequestBinder ¶ added in v0.2.0
type DefaultRequestBinder struct{}
func (*DefaultRequestBinder) Bind ¶ added in v0.2.0
func (b *DefaultRequestBinder) Bind(req *Request, v any) error
Bind implements the DefaultRequestBinder.Bind function. Binding is done in following order: 1) request body; 2) query params. Each step COULD override previous step bound values. For single source binding use their own methods BindBody, BindQueryParams.
func (*DefaultRequestBinder) BindBody ¶ added in v0.2.0
func (b *DefaultRequestBinder) BindBody(req *Request, i any) (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 (*DefaultRequestBinder) BindQueryParams ¶ added in v0.2.0
func (b *DefaultRequestBinder) BindQueryParams(req *Request, i any) error
BindQueryParams binds query params to bindable object.
type HTTPError ¶
HTTPError represents an error that occurred while handling a request.
func NewHTTPError ¶
NewHTTPError creates a new HTTPError instance.
func WrapHTTPError ¶
WrapHTTPError creates a new HTTPError instance with internal error set.
type HTTPErrorHandlerFunc ¶
HTTPErrorHandlerFunc is a centralised handler for HTTPError.
func HandleHTTPError ¶
func HandleHTTPError(expose bool) HTTPErrorHandlerFunc
HandleHTTPError returns the default HTTPErrorHandler used. If expose is true, returned response will be the internal error message.
type HandlerFunc ¶
HandlerFunc is an adapter to allow the use of ordinary functions as HTTP handlers, with *Request and *Responder as parameters.
If f is a function with the appropriate signature, HandlerFunc(f) is a http.Handler that calls f.
func H ¶
func H(handler http.Handler) HandlerFunc
H is a convenient adapter that wraps the translation of http.Handler to HandlerFunc. It returns the error returned by the handler for the caller (typically a middleware) to handle it.
func (HandlerFunc) ServeHTTP ¶
func (h HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP wraps http.Request into Request and http.ResponseWriter into Responder before passing them into and call h(req, res).
Since this function is called once for each handler and middleware, error returned on each layer is handled immediately.
type Request ¶
type Request struct { *http.Request // inherit from http.Request // contains filtered or unexported fields }
Request wraps an *http.Request. See: https://golang.org/pkg/net/http/#Request
func NewRequest ¶
NewRequest creates a new instance of Request.
func (*Request) Bind ¶
Bind binds data from request body to v. Immediately panic if RequestBinder is not set in advance.
func (*Request) FormFile ¶
func (r *Request) FormFile(name string) (*multipart.FileHeader, error)
FormFile returns the multipart form file for the provided name.
func (*Request) FormParams ¶
FormParams returns the form parameters as url.Values.
func (*Request) GetValue ¶
GetValue gets a value by key from the underlying http.Request's context.Context. The context can be retrieved using Request.Context().
func (*Request) IsWebSocket ¶
IsWebSocket returns true if HTTP connection is WebSocket otherwise false.
func (*Request) MultipartForm ¶
MultipartForm returns the multipart form.
func (*Request) QueryParam ¶
QueryParam returns the query param for the provided name.
func (*Request) QueryParams ¶
QueryParams returns the query parameters as url.Values.
func (*Request) QueryString ¶
QueryString returns the URL query string.
type Responder ¶
type Responder struct { Size int64 Committed bool StatusCode int Writer http.ResponseWriter // contains filtered or unexported fields }
Responder wraps an http.ResponseWriter and implements its interface to be used by an HTTP handler to construct an HTTP response. See: https://golang.org/pkg/net/http/#ResponseWriter
func NewResponder ¶
func NewResponder(w http.ResponseWriter) *Responder
NewResponder creates a new instance of Responder.
func (*Responder) After ¶
func (r *Responder) After(fn func())
After registers a function which is called just after the response is written. If the Content-Length is unknown, none of the after function is executed.
func (*Responder) Before ¶
func (r *Responder) Before(fn func())
Before registers a function which is called just before the response is written.
func (*Responder) Flush ¶
func (r *Responder) Flush()
Flush implements the http.Flusher interface to allow an HTTP handler to flush buffered data to the client. See http.Flusher(https://golang.org/pkg/net/http/#Flusher)
func (*Responder) Header ¶
Header returns the header map for the writer that will be sent by WriteHeader. Changing the header after a call to WriteHeader (or Write) has no effect unless the modified headers were declared as trailers by setting the "Trailer" header before the call to WriteHeader (see example) To suppress implicit response headers, set their value to nil. Example: https://golang.org/pkg/net/http/#example_ResponseWriter_trailers
func (*Responder) Hijack ¶
Hijack implements the http.Hijacker interface to allow an HTTP handler to take over the connection. See http.Hijacker(https://golang.org/pkg/net/http/#Hijacker)
func (*Responder) WriteHeader ¶
WriteHeader sends an HTTP response header with status code. If WriteHeader is not called explicitly, the first call to Write will trigger an implicit WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly used to send error codes.
type ValueBinder ¶ added in v0.2.0
type ValueBinder struct { // ValueFunc is used to get single parameter (first) value from request. ValueFunc func(sourceParam string) string // ValuesFunc is used to get all values for parameter from request. i.e. `/api/search?ids=1&ids=2`. ValuesFunc func(sourceParam string) []string // ErrorFunc is used to create errors. Allows you to use your own error type, that for example marshals to your specific json response. ErrorFunc func(sourceParam string, values []string, message string, err error) error // contains filtered or unexported fields }
ValueBinder provides utility methods for binding parameters to various Go built-in types.
func FormParamsBinder ¶ added in v0.2.0
func FormParamsBinder(req *Request) *ValueBinder
FormParamsBinder creates form param binder. For all requests, FormParamsBinder parses the raw query from the URL and uses query params as form params.
For POST, PUT, and PATCH requests, it also reads the request body, parses it as a form and uses query params as form params. Request body parameters take precedence over URL query string values in Request.Form.
NB: when 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
func QueryParamsBinder ¶ added in v0.2.0
func QueryParamsBinder(req *Request) *ValueBinder
QueryParamsBinder creates query parameter value binder.
func (*ValueBinder) BindError ¶ added in v0.2.0
func (b *ValueBinder) BindError() error
BindError returns first seen bind error and resets/empties binder errors for further calls.
func (*ValueBinder) BindErrors ¶ added in v0.2.0
func (b *ValueBinder) BindErrors() []error
BindErrors returns all bind errors and resets/empties binder errors for further calls.
func (*ValueBinder) BindUnmarshaler ¶ added in v0.2.0
func (b *ValueBinder) BindUnmarshaler(sourceParam string, dest BindUnmarshaler) *ValueBinder
BindUnmarshaler binds parameter to destination implementing BindUnmarshaler interface.
func (*ValueBinder) BindWithDelimiter ¶ added in v0.2.0
func (b *ValueBinder) BindWithDelimiter(sourceParam string, dest any, delimiter string) *ValueBinder
BindWithDelimiter binds parameter to destination by suitable conversion function. Delimiter is used before conversion to split parameter value to separate values.
func (*ValueBinder) Bool ¶ added in v0.2.0
func (b *ValueBinder) Bool(sourceParam string, dest *bool) *ValueBinder
Bool binds parameter to bool variable.
func (*ValueBinder) Bools ¶ added in v0.2.0
func (b *ValueBinder) Bools(sourceParam string, dest *[]bool) *ValueBinder
Bools binds parameter values to slice of bool variables.
func (*ValueBinder) Byte ¶ added in v0.2.0
func (b *ValueBinder) Byte(sourceParam string, dest *byte) *ValueBinder
Byte binds parameter to byte variable.
func (*ValueBinder) CustomFunc ¶ added in v0.2.0
func (b *ValueBinder) CustomFunc(sourceParam string, customFunc func(values []string) []error) *ValueBinder
CustomFunc binds parameter values with Func. Func is called only when parameter values exist.
func (*ValueBinder) Duration ¶ added in v0.2.0
func (b *ValueBinder) Duration(sourceParam string, dest *time.Duration) *ValueBinder
Duration binds parameter to time.Duration variable.
func (*ValueBinder) Durations ¶ added in v0.2.0
func (b *ValueBinder) Durations(sourceParam string, dest *[]time.Duration) *ValueBinder
Durations binds parameter values to slice of time.Duration variables.
func (*ValueBinder) FailFast ¶ added in v0.2.0
func (b *ValueBinder) FailFast(value bool) *ValueBinder
FailFast set internal flag to indicate if binding methods will return early (without binding) when previous bind failed.
NB: call this method before any other binding methods as it modifies binding methods behaviour
func (*ValueBinder) Float32 ¶ added in v0.2.0
func (b *ValueBinder) Float32(sourceParam string, dest *float32) *ValueBinder
Float32 binds parameter to float32 variable.
func (*ValueBinder) Float32s ¶ added in v0.2.0
func (b *ValueBinder) Float32s(sourceParam string, dest *[]float32) *ValueBinder
Float32s binds parameter values to slice of float32 variables.
func (*ValueBinder) Float64 ¶ added in v0.2.0
func (b *ValueBinder) Float64(sourceParam string, dest *float64) *ValueBinder
Float64 binds parameter to float64 variable.
func (*ValueBinder) Float64s ¶ added in v0.2.0
func (b *ValueBinder) Float64s(sourceParam string, dest *[]float64) *ValueBinder
Float64s binds parameter values to slice of float64 variables.
func (*ValueBinder) Int ¶ added in v0.2.0
func (b *ValueBinder) Int(sourceParam string, dest *int) *ValueBinder
Int binds parameter to int variable.
func (*ValueBinder) Int16 ¶ added in v0.2.0
func (b *ValueBinder) Int16(sourceParam string, dest *int16) *ValueBinder
Int16 binds parameter to int16 variable.
func (*ValueBinder) Int16s ¶ added in v0.2.0
func (b *ValueBinder) Int16s(sourceParam string, dest *[]int16) *ValueBinder
Int16s binds parameter to slice of int16.
func (*ValueBinder) Int32 ¶ added in v0.2.0
func (b *ValueBinder) Int32(sourceParam string, dest *int32) *ValueBinder
Int32 binds parameter to int32 variable.
func (*ValueBinder) Int32s ¶ added in v0.2.0
func (b *ValueBinder) Int32s(sourceParam string, dest *[]int32) *ValueBinder
Int32s binds parameter to slice of int32.
func (*ValueBinder) Int64 ¶ added in v0.2.0
func (b *ValueBinder) Int64(sourceParam string, dest *int64) *ValueBinder
Int64 binds parameter to int64 variable.
func (*ValueBinder) Int64s ¶ added in v0.2.0
func (b *ValueBinder) Int64s(sourceParam string, dest *[]int64) *ValueBinder
Int64s binds parameter to slice of int64.
func (*ValueBinder) Int8 ¶ added in v0.2.0
func (b *ValueBinder) Int8(sourceParam string, dest *int8) *ValueBinder
Int8 binds parameter to int8 variable.
func (*ValueBinder) Int8s ¶ added in v0.2.0
func (b *ValueBinder) Int8s(sourceParam string, dest *[]int8) *ValueBinder
Int8s binds parameter to slice of int8.
func (*ValueBinder) Ints ¶ added in v0.2.0
func (b *ValueBinder) Ints(sourceParam string, dest *[]int) *ValueBinder
Ints binds parameter to slice of int.
func (*ValueBinder) MustBindUnmarshaler ¶ added in v0.2.0
func (b *ValueBinder) MustBindUnmarshaler(sourceParam string, dest BindUnmarshaler) *ValueBinder
MustBindUnmarshaler requires parameter value to exist to be bind to destination implementing BindUnmarshaler interface. Returns error when value does not exist.
func (*ValueBinder) MustBindWithDelimiter ¶ added in v0.2.0
func (b *ValueBinder) MustBindWithDelimiter(sourceParam string, dest any, delimiter string) *ValueBinder
MustBindWithDelimiter requires parameter value to exist to be bind destination by suitable conversion function. Delimiter is used before conversion to split parameter value to separate values.
func (*ValueBinder) MustBool ¶ added in v0.2.0
func (b *ValueBinder) MustBool(sourceParam string, dest *bool) *ValueBinder
MustBool requires parameter value to exist to be bind to bool variable. Returns error when value does not exist.
func (*ValueBinder) MustBools ¶ added in v0.2.0
func (b *ValueBinder) MustBools(sourceParam string, dest *[]bool) *ValueBinder
MustBools requires parameter values to exist to be bind to slice of bool variables. Returns error when values does not exist.
func (*ValueBinder) MustByte ¶ added in v0.2.0
func (b *ValueBinder) MustByte(sourceParam string, dest *byte) *ValueBinder
MustByte requires parameter value to exist to be bind to byte variable. Returns error when value does not exist.
func (*ValueBinder) MustCustomFunc ¶ added in v0.2.0
func (b *ValueBinder) MustCustomFunc(sourceParam string, customFunc func(values []string) []error) *ValueBinder
MustCustomFunc requires parameter values to exist to be bind with Func. Returns error when value does not exist.
func (*ValueBinder) MustDuration ¶ added in v0.2.0
func (b *ValueBinder) MustDuration(sourceParam string, dest *time.Duration) *ValueBinder
MustDuration requires parameter value to exist to be bind to time.Duration variable. Returns error when value does not exist.
func (*ValueBinder) MustDurations ¶ added in v0.2.0
func (b *ValueBinder) MustDurations(sourceParam string, dest *[]time.Duration) *ValueBinder
MustDurations requires parameter values to exist to be bind to slice of time.Duration variables. Returns error when values does not exist.
func (*ValueBinder) MustFloat32 ¶ added in v0.2.0
func (b *ValueBinder) MustFloat32(sourceParam string, dest *float32) *ValueBinder
MustFloat32 requires parameter value to exist to be bind to float32 variable. Returns error when value does not exist.
func (*ValueBinder) MustFloat32s ¶ added in v0.2.0
func (b *ValueBinder) MustFloat32s(sourceParam string, dest *[]float32) *ValueBinder
MustFloat32s requires parameter values to exist to be bind to slice of float32 variables. Returns error when values does not exist.
func (*ValueBinder) MustFloat64 ¶ added in v0.2.0
func (b *ValueBinder) MustFloat64(sourceParam string, dest *float64) *ValueBinder
MustFloat64 requires parameter value to exist to be bind to float64 variable. Returns error when value does not exist.
func (*ValueBinder) MustFloat64s ¶ added in v0.2.0
func (b *ValueBinder) MustFloat64s(sourceParam string, dest *[]float64) *ValueBinder
MustFloat64s requires parameter values to exist to be bind to slice of float64 variables. Returns error when values does not exist.
func (*ValueBinder) MustInt ¶ added in v0.2.0
func (b *ValueBinder) MustInt(sourceParam string, dest *int) *ValueBinder
MustInt requires parameter value to exist to be bind to int variable. Returns error when value does not exist.
func (*ValueBinder) MustInt16 ¶ added in v0.2.0
func (b *ValueBinder) MustInt16(sourceParam string, dest *int16) *ValueBinder
MustInt16 requires parameter value to exist to be bind to int16 variable. Returns error when value does not exist.
func (*ValueBinder) MustInt16s ¶ added in v0.2.0
func (b *ValueBinder) MustInt16s(sourceParam string, dest *[]int16) *ValueBinder
MustInt16s requires parameter value to exist to be bind to int16 slice variable. Returns error when value does not exist.
func (*ValueBinder) MustInt32 ¶ added in v0.2.0
func (b *ValueBinder) MustInt32(sourceParam string, dest *int32) *ValueBinder
MustInt32 requires parameter value to exist to be bind to int32 variable. Returns error when value does not exist.
func (*ValueBinder) MustInt32s ¶ added in v0.2.0
func (b *ValueBinder) MustInt32s(sourceParam string, dest *[]int32) *ValueBinder
MustInt32s requires parameter value to exist to be bind to int32 slice variable. Returns error when value does not exist.
func (*ValueBinder) MustInt64 ¶ added in v0.2.0
func (b *ValueBinder) MustInt64(sourceParam string, dest *int64) *ValueBinder
MustInt64 requires parameter value to exist to be bind to int64 variable. Returns error when value does not exist
func (*ValueBinder) MustInt64s ¶ added in v0.2.0
func (b *ValueBinder) MustInt64s(sourceParam string, dest *[]int64) *ValueBinder
MustInt64s requires parameter value to exist to be bind to int64 slice variable. Returns error when value does not exist.
func (*ValueBinder) MustInt8 ¶ added in v0.2.0
func (b *ValueBinder) MustInt8(sourceParam string, dest *int8) *ValueBinder
MustInt8 requires parameter value to exist to be bind to int8 variable. Returns error when value does not exist.
func (*ValueBinder) MustInt8s ¶ added in v0.2.0
func (b *ValueBinder) MustInt8s(sourceParam string, dest *[]int8) *ValueBinder
MustInt8s requires parameter value to exist to be bind to int8 slice variable. Returns error when value does not exist.
func (*ValueBinder) MustInts ¶ added in v0.2.0
func (b *ValueBinder) MustInts(sourceParam string, dest *[]int) *ValueBinder
MustInts requires parameter value to exist to be bind to int slice variable. Returns error when value does not exist.
func (*ValueBinder) MustString ¶ added in v0.2.0
func (b *ValueBinder) MustString(sourceParam string, dest *string) *ValueBinder
MustString requires parameter value to exist to be bind to string variable. Returns error when value does not exist.
func (*ValueBinder) MustStrings ¶ added in v0.2.0
func (b *ValueBinder) MustStrings(sourceParam string, dest *[]string) *ValueBinder
MustStrings requires parameter values to exist to be bind to slice of string variables. Returns error when value does not exist.
func (*ValueBinder) MustTime ¶ added in v0.2.0
func (b *ValueBinder) MustTime(sourceParam string, dest *time.Time, layout string) *ValueBinder
MustTime requires parameter value to exist to be bind to time.Time variable. Returns error when value does not exist.
func (*ValueBinder) MustTimes ¶ added in v0.2.0
func (b *ValueBinder) MustTimes(sourceParam string, dest *[]time.Time, layout string) *ValueBinder
MustTimes requires parameter values to exist to be bind to slice of time.Time variables. Returns error when values does not exist.
func (*ValueBinder) MustUint ¶ added in v0.2.0
func (b *ValueBinder) MustUint(sourceParam string, dest *uint) *ValueBinder
MustUint requires parameter value to exist to be bind to uint variable. Returns error when value does not exist.
func (*ValueBinder) MustUint16 ¶ added in v0.2.0
func (b *ValueBinder) MustUint16(sourceParam string, dest *uint16) *ValueBinder
MustUint16 requires parameter value to exist to be bind to uint16 variable. Returns error when value does not exist.
func (*ValueBinder) MustUint16s ¶ added in v0.2.0
func (b *ValueBinder) MustUint16s(sourceParam string, dest *[]uint16) *ValueBinder
MustUint16s requires parameter value to exist to be bind to uint16 slice variable. Returns error when value does not exist.
func (*ValueBinder) MustUint32 ¶ added in v0.2.0
func (b *ValueBinder) MustUint32(sourceParam string, dest *uint32) *ValueBinder
MustUint32 requires parameter value to exist to be bind to uint32 variable. Returns error when value does not exist.
func (*ValueBinder) MustUint32s ¶ added in v0.2.0
func (b *ValueBinder) MustUint32s(sourceParam string, dest *[]uint32) *ValueBinder
MustUint32s requires parameter value to exist to be bind to uint32 slice variable. Returns error when value does not exist.
func (*ValueBinder) MustUint64 ¶ added in v0.2.0
func (b *ValueBinder) MustUint64(sourceParam string, dest *uint64) *ValueBinder
MustUint64 requires parameter value to exist to be bind to uint64 variable. Returns error when value does not exist.
func (*ValueBinder) MustUint64s ¶ added in v0.2.0
func (b *ValueBinder) MustUint64s(sourceParam string, dest *[]uint64) *ValueBinder
MustUint64s requires parameter value to exist to be bind to uint64 slice variable. Returns error when value does not exist.
func (*ValueBinder) MustUint8 ¶ added in v0.2.0
func (b *ValueBinder) MustUint8(sourceParam string, dest *uint8) *ValueBinder
MustUint8 requires parameter value to exist to be bind to uint8 variable. Returns error when value does not exist.
func (*ValueBinder) MustUint8s ¶ added in v0.2.0
func (b *ValueBinder) MustUint8s(sourceParam string, dest *[]uint8) *ValueBinder
MustUint8s requires parameter value to exist to be bind to uint8 slice variable. Returns error when value does not exist.
func (*ValueBinder) MustUints ¶ added in v0.2.0
func (b *ValueBinder) MustUints(sourceParam string, dest *[]uint) *ValueBinder
MustUints requires parameter value to exist to be bind to uint slice variable. Returns error when value does not exist.
func (*ValueBinder) MustUnixTime ¶ added in v0.2.0
func (b *ValueBinder) MustUnixTime(sourceParam string, dest *time.Time) *ValueBinder
MustUnixTime requires parameter value to exist to be bind to time.Duration variable (in local Time corresponding to the given Unix time). Returns error when value does not exist.
Example: 1609180603 bind to 2020-12-28T18:36:43.000000000+00:00
Note:
- time.Time{} (param is empty) and time.Unix(0,0) (param = "0") are not equal
func (*ValueBinder) MustUnixTimeNano ¶ added in v0.2.0
func (b *ValueBinder) MustUnixTimeNano(sourceParam string, dest *time.Time) *ValueBinder
MustUnixTimeNano requires parameter value to exist to be bind to time.Duration variable (in local Time corresponding to the given Unix time value in nano second precision). Returns error when value does not exist.
Example: 1609180603123456789 binds to 2020-12-28T18:36:43.123456789+00:00 Example: 1000000000 binds to 1970-01-01T00:00:01.000000000+00:00 Example: 999999999 binds to 1970-01-01T00:00:00.999999999+00:00
Note:
- time.Time{} (param is empty) and time.Unix(0,0) (param = "0") are not equal
- Javascript's Number type only has about 53 bits of precision (Number.MAX_SAFE_INTEGER = 9007199254740991). Compare it to 1609180603123456789 in example
func (*ValueBinder) String ¶ added in v0.2.0
func (b *ValueBinder) String(sourceParam string, dest *string) *ValueBinder
String binds parameter to string variable.
func (*ValueBinder) Strings ¶ added in v0.2.0
func (b *ValueBinder) Strings(sourceParam string, dest *[]string) *ValueBinder
Strings binds parameter values to slice of string.
func (*ValueBinder) Time ¶ added in v0.2.0
func (b *ValueBinder) Time(sourceParam string, dest *time.Time, layout string) *ValueBinder
Time binds parameter to time.Time variable.
func (*ValueBinder) Times ¶ added in v0.2.0
func (b *ValueBinder) Times(sourceParam string, dest *[]time.Time, layout string) *ValueBinder
Times binds parameter values to slice of time.Time variables.
func (*ValueBinder) Uint ¶ added in v0.2.0
func (b *ValueBinder) Uint(sourceParam string, dest *uint) *ValueBinder
Uint binds parameter to uint variable.
func (*ValueBinder) Uint16 ¶ added in v0.2.0
func (b *ValueBinder) Uint16(sourceParam string, dest *uint16) *ValueBinder
Uint16 binds parameter to uint16 variable.
func (*ValueBinder) Uint16s ¶ added in v0.2.0
func (b *ValueBinder) Uint16s(sourceParam string, dest *[]uint16) *ValueBinder
Uint16s binds parameter to slice of uint16.
func (*ValueBinder) Uint32 ¶ added in v0.2.0
func (b *ValueBinder) Uint32(sourceParam string, dest *uint32) *ValueBinder
Uint32 binds parameter to uint32 variable.
func (*ValueBinder) Uint32s ¶ added in v0.2.0
func (b *ValueBinder) Uint32s(sourceParam string, dest *[]uint32) *ValueBinder
Uint32s binds parameter to slice of uint32.
func (*ValueBinder) Uint64 ¶ added in v0.2.0
func (b *ValueBinder) Uint64(sourceParam string, dest *uint64) *ValueBinder
Uint64 binds parameter to uint64 variable.
func (*ValueBinder) Uint64s ¶ added in v0.2.0
func (b *ValueBinder) Uint64s(sourceParam string, dest *[]uint64) *ValueBinder
Uint64s binds parameter to slice of uint64.
func (*ValueBinder) Uint8 ¶ added in v0.2.0
func (b *ValueBinder) Uint8(sourceParam string, dest *uint8) *ValueBinder
Uint8 binds parameter to uint8 variable.
func (*ValueBinder) Uint8s ¶ added in v0.2.0
func (b *ValueBinder) Uint8s(sourceParam string, dest *[]uint8) *ValueBinder
Uint8s binds parameter to slice of uint8.
func (*ValueBinder) Uints ¶ added in v0.2.0
func (b *ValueBinder) Uints(sourceParam string, dest *[]uint) *ValueBinder
Uints binds parameter to slice of uint.
func (*ValueBinder) UnixTime ¶ added in v0.2.0
func (b *ValueBinder) UnixTime(sourceParam string, dest *time.Time) *ValueBinder
UnixTime binds parameter to time.Time variable (in local Time corresponding to the given Unix time).
Example: 1609180603 bind to 2020-12-28T18:36:43.000000000+00:00
Note:
- time.Time{} (param is empty) and time.Unix(0,0) (param = "0") are not equal
func (*ValueBinder) UnixTimeNano ¶ added in v0.2.0
func (b *ValueBinder) UnixTimeNano(sourceParam string, dest *time.Time) *ValueBinder
UnixTimeNano binds parameter to time.Time variable (in local Time corresponding to the given Unix time in nano second precision).
Example: 1609180603123456789 binds to 2020-12-28T18:36:43.123456789+00:00 Example: 1000000000 binds to 1970-01-01T00:00:01.000000000+00:00 Example: 999999999 binds to 1970-01-01T00:00:00.999999999+00:00
Note:
- time.Time{} (param is empty) and time.Unix(0,0) (param = "0") are not equal
- Javascript's Number type only has about 53 bits of precision (Number.MAX_SAFE_INTEGER = 9007199254740991). Compare it to 1609180603123456789 in example