-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvelope.go
39 lines (34 loc) · 1.11 KB
/
nvelope.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
37
38
39
package nape
import (
"encoding/json"
"encoding/xml"
"net/http"
"github.com/muir/nvelope"
"github.com/gorilla/mux"
)
// DecodeJSON is is a pre-defined special nject.Provider created with
// nvelope.GenerateDecoder for decoding JSON requests. Use it with the
// other features of https://github.com/muir/nvelope
var DecodeJSON = nvelope.GenerateDecoder(
nvelope.WithDecoder("application/json", json.Unmarshal),
nvelope.WithDefaultContentType("application/json"),
nvelope.WithPathVarsFunction(func(r *http.Request) nvelope.RouteVarLookup {
vars := mux.Vars(r)
return func(v string) string {
return vars[v]
}
}),
)
// DecodeXML is is a pre-defined special nject.Provider created with
// nvelope.GenerateDecoder for decoding XML requests.Use it with the
// other features of https://github.com/muir/nvelope
var DecodeXML = nvelope.GenerateDecoder(
nvelope.WithDecoder("application/xml", xml.Unmarshal),
nvelope.WithDefaultContentType("application/xml"),
nvelope.WithPathVarsFunction(func(r *http.Request) nvelope.RouteVarLookup {
vars := mux.Vars(r)
return func(v string) string {
return vars[v]
}
}),
)