-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapirest.go
89 lines (73 loc) · 1.8 KB
/
apirest.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package apirest
import (
"net/http"
"github.com/jgolang/apirest/core"
)
// PPPGMethodsKey POST, PUT, PATCH, and GET http methods ..
const PPPGMethodsKey = "pppg"
// PPPMethodsKey POST, PUT and PATCH http methods ..
const PPPMethodsKey = "ppp"
// PPMethodsKey POST and PUT http methods ..
const PPMethodsKey = "pp"
// MethodPostKey POST http method key ..
const MethodPostKey = "post"
// MethodGetKey GET http method key ..
const MethodGetKey = "get"
// MethodPutKey PUT http method key ..
const MethodPutKey = "put"
// MethodPatchKey http method key ..
const MethodPatchKey = "patch"
var api = core.New(
RequestValidator{},
ResponseFormatter{},
Responder{},
&Security{},
&mapMethods,
)
// RegisterNewAPIFormatter doc ...
func RegisterNewAPIFormatter(f core.APIResponseFormatter) {
api.RegisterNewAPIResponseFormatter(f)
}
// RegisterNewAPIResponder doc ...
func RegisterNewAPIResponder(f core.APIResponder) {
api.RegisterNewAPIResponder(f)
}
// RegisterNewAPIRequestValidator doc ...
func RegisterNewAPIRequestValidator(v core.APIRequestValidater) {
api.RegisterNewAPIRequestValidator(v)
}
// AddNewMapMethod doc ...
func AddNewMapMethod(key string, methods []string) {
api.AddMapMethod(key, methods)
}
var mapMethods core.MapMethods
func init() {
mapMethods = make(core.MapMethods)
mapMethods[PPPGMethodsKey] = []string{
http.MethodPost,
http.MethodGet,
http.MethodPut,
http.MethodPatch,
}
mapMethods[PPPMethodsKey] = []string{
http.MethodPost,
http.MethodPut,
http.MethodPatch,
}
mapMethods[PPMethodsKey] = []string{
http.MethodPost,
http.MethodPut,
}
mapMethods[MethodPostKey] = []string{
http.MethodPost,
}
mapMethods[MethodGetKey] = []string{
http.MethodGet,
}
mapMethods[MethodPutKey] = []string{
http.MethodPut,
}
mapMethods[MethodPutKey] = []string{
http.MethodPut,
}
}