Skip to content

Commit

Permalink
add DecodeHeaders
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Aug 31, 2020
1 parent c724b24 commit 35b4e06
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", "param", "schema"},
tags: []string{"form", "url", "header", "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,13 +1,15 @@
package schema

var (
defaultDecoder = NewDecoder() // form, url, param, schema.
defaultDecoder = NewDecoder() // form, url, header, 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
// Headers Decoder. The default instance for DecodeHeaders function.
Headers = NewDecoder().SetAliasTag("header").IgnoreUnknownKeys(true)
// Params Decoder. The default instance for DecodeParams function.
Params = NewDecoder().SetAliasTag("param").IgnoreUnknownKeys(true) // and dynamic path parameters.
Params = NewDecoder().SetAliasTag("param").IgnoreUnknownKeys(true)
)

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

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

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

0 comments on commit 35b4e06

Please sign in to comment.