Documentation ¶
Index ¶
- type ReturnOfType
- type ReturnTarget
- type StringParser
- type StrongParams
- func (this *StrongParams) Permit(permitRule string, permitRules ...string) *StrongParamsRequiredAndPermitted
- func (this *StrongParams) PostForm(request *http.Request) ReturnTarget
- func (this *StrongParams) Query(request *http.Request) ReturnTarget
- func (this *StrongParams) Require(requireKey string) *StrongParamsRequired
- func (this *StrongParams) RequireOne(requireKey string) *StrongParamsRequireOne
- func (this *StrongParams) Values(values url.Values) ReturnTarget
- func (this *StrongParams) WithDecoder(decoder *schema.Decoder) *StrongParams
- type StrongParamsRequireOne
- type StrongParamsRequired
- func (this *StrongParamsRequired) Permit(permitRule string, permitRules ...string) *StrongParamsRequiredAndPermitted
- func (this *StrongParamsRequired) PostForm(request *http.Request) ReturnTarget
- func (this *StrongParamsRequired) Query(request *http.Request) ReturnTarget
- func (this *StrongParamsRequired) Values(values url.Values) ReturnTarget
- type StrongParamsRequiredAndPermitted
- type StrongParamsWithDecoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ReturnOfType ¶
type ReturnOfType func(StringParser) (interface{}, error)
ReturnOfType enables parsing and returning the single key from url.Values declared by StrongParams.RequireOne method or returns an error if it fails.
The StringParser parameter shall be a function definition that enables parsing string value to specific required type.
type ReturnTarget ¶
type ReturnTarget func(target interface{}) error
ReturnTarget enables just features of schema.Decoder (https://github.com/gorilla/schema) without performing any additional checks. schema.Decoder requires a dot notation of properties eg. "root.0.key" equivalent to query string "root[0][key]". Given method enables using the standard query string brackets format with schema.Decoder. Before passing the url.Values to schema.Decoder the keys are transposed to the required dot notation.
The `target` parameter shall be a pointer to the parsable struct.
type StringParser ¶
type StringParser interface{}
StringParser should be a function of:
func(string) {<any output type>, error}
The interface will be checked by the runner. If it doesn't comply it will panic.
type StrongParams ¶
type StrongParams struct {
// contains filtered or unexported fields
}
func Params ¶
func Params() *StrongParams
Params declares the *http.Request to be used for the strong parameters mechanism.
**NOTE** The method panics if the passed request parameter is nil.
func (*StrongParams) Permit ¶
func (this *StrongParams) Permit(permitRule string, permitRules ...string) *StrongParamsRequiredAndPermitted
Permit instructs to apply the rules to whitelist the keys in url.Values before decoding it to the target struct.
func (*StrongParams) PostForm ¶
func (this *StrongParams) PostForm(request *http.Request) ReturnTarget
PostForm instructs the mechanism to process http.Request's url.PostForm property's url.Values.
func (*StrongParams) Query ¶
func (this *StrongParams) Query(request *http.Request) ReturnTarget
Query instructs the mechanism to process http.Request's url.URL property url.URL/Query() method returned url.Values.
func (*StrongParams) Require ¶
func (this *StrongParams) Require(requireKey string) *StrongParamsRequired
Require instructs to ensure before processing that the processable url.Values has by `requireKey` parameter provided root key. The chained StrongParamsRequired.Permit rules are applied on the object found behind the parameter `requireKey` defined key.
Go: Params().Require("root").Permit("sub:{key}") Whitelisted query: root[sub][key]=value
The `requireKey` value cannot be empty. Otherwise an error is produced but not returned until executing ReturnTarget function.
func (*StrongParams) RequireOne ¶
func (this *StrongParams) RequireOne(requireKey string) *StrongParamsRequireOne
RequireOne instructs to ensure presence and parse a single value in url.Values. `requireKey` parameter defines the key to retrieve from the url.Values.
func (*StrongParams) Values ¶
func (this *StrongParams) Values(values url.Values) ReturnTarget
Values instructs the mechanism to process url.Values from `values` parameter.
func (*StrongParams) WithDecoder ¶
func (this *StrongParams) WithDecoder(decoder *schema.Decoder) *StrongParams
StrongParams.WithDecoder instructs the strong-parameters mechanism to use explicit decoder. The new decoder will be used on the returned *StrongParams struct pointer not on the receiver parameter. To use new implicitly defined schema.Decoder, look WithDecoder method instead.
type StrongParamsRequireOne ¶
type StrongParamsRequireOne struct {
// contains filtered or unexported fields
}
func (*StrongParamsRequireOne) PostForm ¶
func (this *StrongParamsRequireOne) PostForm(request *http.Request) ReturnOfType
PostForm instructs the mechanism to process http.Request's url.PostForm property's url.Values.
func (*StrongParamsRequireOne) Query ¶
func (this *StrongParamsRequireOne) Query(request *http.Request) ReturnOfType
Query instructs the mechanism to process http.Request's url.URL property url.URL/Query() method returned url.Values.
func (*StrongParamsRequireOne) Values ¶
func (this *StrongParamsRequireOne) Values(values url.Values) ReturnOfType
Values instructs the mechanism to process url.Values from `values` parameter.
type StrongParamsRequired ¶
type StrongParamsRequired struct {
// contains filtered or unexported fields
}
func (*StrongParamsRequired) Permit ¶
func (this *StrongParamsRequired) Permit(permitRule string, permitRules ...string) *StrongParamsRequiredAndPermitted
Permit instructs to apply the rules to whitelist the keys in url.Values before decoding it to the target struct. The chained Permit rules are applied on the object found behind the parameter `requireKey` defined key instructed by StrongParams.Require method.
Go: Params().Require("root").Permit("sub:{key}") Whitelisted query: root[sub][key]=value
These two use cases are equivalent:
Permit("[key1, key2]") Permit("key1", "key2")
func (*StrongParamsRequired) PostForm ¶
func (this *StrongParamsRequired) PostForm(request *http.Request) ReturnTarget
PostForm instructs the mechanism to process http.Request's url.PostForm property's url.Values.
func (*StrongParamsRequired) Query ¶
func (this *StrongParamsRequired) Query(request *http.Request) ReturnTarget
Query instructs the mechanism to process http.Request's url.URL property url.URL/Query() method returned url.Values.
func (*StrongParamsRequired) Values ¶
func (this *StrongParamsRequired) Values(values url.Values) ReturnTarget
Values instructs the mechanism to process url.Values from `values` parameter.
type StrongParamsRequiredAndPermitted ¶
type StrongParamsRequiredAndPermitted struct {
// contains filtered or unexported fields
}
func (*StrongParamsRequiredAndPermitted) PostForm ¶
func (this *StrongParamsRequiredAndPermitted) PostForm(request *http.Request) ReturnTarget
PostForm instructs the mechanism to process http.Request's url.PostForm property's url.Values.
func (*StrongParamsRequiredAndPermitted) Query ¶
func (this *StrongParamsRequiredAndPermitted) Query(request *http.Request) ReturnTarget
Query instructs the mechanism to process http.Request's url.URL property url.URL/Query() method returned url.Values.
func (*StrongParamsRequiredAndPermitted) Values ¶
func (this *StrongParamsRequiredAndPermitted) Values(values url.Values) ReturnTarget
Values instructs the mechanism to process url.Values from `values` parameter.
type StrongParamsWithDecoder ¶
type StrongParamsWithDecoder struct {
// contains filtered or unexported fields
}
func WithDecoder ¶
func WithDecoder(decoder *schema.Decoder) (*StrongParamsWithDecoder, error)
WithDecoder declares the decoder to be used for Params mechanism.
paramsWithDecoder, err := WithDecoder(schema.NewDecoder()) // handle error queryParams := paramsWithDecoder.Params(request).Query()
Returns an error if the passed decoder is a `nil` value.
func WithDecoderSafe ¶
func WithDecoderSafe(decoder *schema.Decoder) *StrongParamsWithDecoder
WithDecoderSafe is an equivalent of WithDecoder but instead of returning an error when the passed decoder is a `nil` value it panics with the same error.
WithDecoder(schema.NewDecoder()).Params(request).Query()
func (*StrongParamsWithDecoder) Params ¶
func (this *StrongParamsWithDecoder) Params() *StrongParams
Params declares the *http.Request to be used for the strong parameters mechanism.
**NOTE** The method panics if the passed request parameter is nil.