-
Notifications
You must be signed in to change notification settings - Fork 1
/
nvelope.go
34 lines (29 loc) · 1.16 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
package nchi
import (
"encoding/json"
"encoding/xml"
"github.com/muir/nvelope"
"github.com/julienschmidt/httprouter"
)
// 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 . DecodeJSON must
// be paired with nvelope.ReadBody to actually decode JSON.
var DecodeJSON = nvelope.GenerateDecoder(
nvelope.WithDecoder("application/json", json.Unmarshal),
nvelope.WithDefaultContentType("application/json"),
nvelope.WithPathVarsFunction(func(p httprouter.Params) nvelope.RouteVarLookup {
return p.ByName
}),
)
// 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 . DecodeXML must be
// paired with nvelope.ReadBody to actually decode XML.
var DecodeXML = nvelope.GenerateDecoder(
nvelope.WithDecoder("application/xml", xml.Unmarshal),
nvelope.WithDefaultContentType("application/xml"),
nvelope.WithPathVarsFunction(func(p httprouter.Params) nvelope.RouteVarLookup {
return p.ByName
}),
)