-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontracts_methods.go
98 lines (84 loc) · 1.91 KB
/
contracts_methods.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
90
91
92
93
94
95
96
97
98
package httprouter
import (
"net/http"
"strings"
)
type Method uint16
func ParseMethods(value string) Method {
var parsed Method
for _, raw := range strings.Split(value, pipeDelimiter) {
parsed |= ParseMethod(raw)
}
return parsed
}
func ParseMethod(value string) Method {
value = strings.ToUpper(strings.TrimSpace(value))
if parsed, found := availableMethods[value]; found {
return parsed
}
return MethodNone
}
func (this Method) String() string {
var result string
for _, key := range orderedMethods {
if key&this != key {
continue
}
if len(result) > 0 {
result += pipeDelimiter
}
result += methodValues[key]
}
return result
}
func (this Method) GoString() string { return this.String() }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const (
MethodNone Method = 1 << iota
MethodGet
MethodHead
MethodPost
MethodPut
MethodDelete
MethodConnect
MethodOptions
MethodTrace
MethodPatch
)
var (
orderedMethods = []Method{
MethodGet,
MethodHead,
MethodPost,
MethodPut,
MethodDelete,
MethodConnect,
MethodOptions,
MethodTrace,
MethodPatch,
}
methodValues = map[Method]string{
MethodNone: "",
MethodGet: http.MethodGet,
MethodHead: http.MethodHead,
MethodPost: http.MethodPost,
MethodPut: http.MethodPut,
MethodDelete: http.MethodDelete,
MethodConnect: http.MethodConnect,
MethodOptions: http.MethodOptions,
MethodTrace: http.MethodTrace,
MethodPatch: http.MethodPatch,
}
availableMethods = map[string]Method{
"": MethodNone,
http.MethodGet: MethodGet,
http.MethodHead: MethodHead,
http.MethodPost: MethodPost,
http.MethodPut: MethodPut,
http.MethodDelete: MethodDelete,
http.MethodConnect: MethodConnect,
http.MethodOptions: MethodOptions,
http.MethodTrace: MethodTrace,
http.MethodPatch: MethodPatch,
}
)