-
Notifications
You must be signed in to change notification settings - Fork 2
/
extractors.go
36 lines (28 loc) · 866 Bytes
/
extractors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package kcd
import (
"net/http"
"github.com/go-chi/chi"
)
// defaultHeaderExtractor is an extractor that operates on the headers
// of a request.
func defaultHeaderExtractor(_ http.ResponseWriter, r *http.Request, tag string) ([]string, error) {
header := r.Header.Get(tag)
if header == "" {
return nil, nil
}
return []string{header}, nil
}
// defaultQueryExtractor is an extractor that operates on the path
// parameters of a request.
func defaultQueryExtractor(_ http.ResponseWriter, r *http.Request, tag string) ([]string, error) {
return r.URL.Query()[tag], nil
}
// defaultPathExtractor is an extractor that operates on the path
// parameters of a request.
func defaultPathExtractor(_ http.ResponseWriter, r *http.Request, tag string) ([]string, error) {
p := chi.URLParam(r, tag)
if p == "" {
return nil, nil
}
return []string{p}, nil
}