Skip to content

Commit

Permalink
add params default decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Aug 31, 2020
1 parent 898d805 commit c724b24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newCache() *cache {
c := cache{
m: make(map[reflect.Type]*structInfo),
regconv: make(map[reflect.Type]Converter),
tags: []string{"form", "url", "schema"},
tags: []string{"form", "url", "param", "schema"},
}
return &c
}
Expand Down
12 changes: 10 additions & 2 deletions schema.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package schema

var (
defaultDecoder = NewDecoder() // form, url, schema.
defaultDecoder = NewDecoder() // form, url, param, schema.
// Form Decoder. The default instance for DecodeForm function.
Form = NewDecoder().SetAliasTag("form")
// Query Decoder. The default instance for DecodeQuery function.
Query = NewDecoder().SetAliasTag("url").IgnoreUnknownKeys(true) // allow unknown url queries.
Query = NewDecoder().SetAliasTag("url").IgnoreUnknownKeys(true) // allow unknown url queries
// Params Decoder. The default instance for DecodeParams function.
Params = NewDecoder().SetAliasTag("param").IgnoreUnknownKeys(true) // and dynamic path parameters.
)

// Decode maps "values" to "ptr".
Expand All @@ -26,6 +28,12 @@ func DecodeQuery(values map[string][]string, ptr interface{}) error {
return Query.Decode(ptr, values)
}

// DecodeParams maps "values" to "ptr".
// With "param" tag for fields.
func DecodeParams(values map[string][]string, ptr interface{}) error {
return Params.Decode(ptr, values)
}

// IsErrPath reports whether the incoming error is type of unknown field passed,
// which can be ignored when server allows unknown post values to be sent by the client.
func IsErrPath(err error) bool {
Expand Down

0 comments on commit c724b24

Please sign in to comment.