-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethod.go
59 lines (53 loc) · 974 Bytes
/
method.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
package router
import "net/http"
type Method int
const (
Get Method = iota
Post
Head
Put
Delete
Patch
Options
Connect
Trace
)
var stringToMethod = map[string]Method{
http.MethodGet: Get,
http.MethodPost: Post,
http.MethodHead: Head,
http.MethodPut: Put,
http.MethodDelete: Delete,
http.MethodPatch: Patch,
http.MethodOptions: Options,
http.MethodConnect: Connect,
http.MethodTrace: Trace,
}
func (m Method) String() string {
switch m {
case Get:
return http.MethodGet
case Post:
return http.MethodPost
case Head:
return http.MethodHead
case Put:
return http.MethodPut
case Delete:
return http.MethodDelete
case Patch:
return http.MethodPatch
case Options:
return http.MethodOptions
case Connect:
return http.MethodConnect
case Trace:
return http.MethodTrace
default:
return "Unknown"
}
}
func MethodFromString(method string) (Method, bool) {
m, exists := stringToMethod[method]
return m, exists
}