✨ Added param extractor
This commit is contained in:
parent
a214a7e9e8
commit
7375a6e8ed
18
extractor.go
18
extractor.go
|
@ -48,6 +48,8 @@ func createExtractors(lookups, authScheme string) ([]ValuesExtractor, error) {
|
|||
switch parts[0] {
|
||||
case "query":
|
||||
extractors = append(extractors, valuesFromQuery(parts[1]))
|
||||
case "param":
|
||||
extractors = append(extractors, valuesFromParam(parts[1]))
|
||||
case "cookie":
|
||||
extractors = append(extractors, valuesFromCookie(parts[1]))
|
||||
case "form":
|
||||
|
@ -121,6 +123,22 @@ func valuesFromQuery(param string) ValuesExtractor {
|
|||
}
|
||||
}
|
||||
|
||||
// valuesFromParam returns a function that extracts values from the url param string.
|
||||
func valuesFromParam(param string) ValuesExtractor {
|
||||
return func(ctx *http.RequestCtx) ([][]byte, error) {
|
||||
if !ctx.PostArgs().Has(param) {
|
||||
return nil, errParamExtractorValueMissing
|
||||
}
|
||||
|
||||
result := ctx.PostArgs().PeekMulti(param)
|
||||
if len(result) > extractorLimit-1 {
|
||||
result = result[:extractorLimit]
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
// valuesFromCookie returns a function that extracts values from the named cookie.
|
||||
func valuesFromCookie(name string) ValuesExtractor {
|
||||
return func(ctx *http.RequestCtx) ([][]byte, error) {
|
||||
|
|
Loading…
Reference in New Issue