-
Notifications
You must be signed in to change notification settings - Fork 10
/
methods.go
101 lines (95 loc) · 1.51 KB
/
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
99
100
101
package service
import "net/http"
// HTTP Methods
const (
Options = iota
Head
Post
Get
Put
Patch
Delete
Connect
Trace
)
// IsMethod returns true if the int value matches one of the iota values for a
// HTTP method
func IsMethod(m int) bool {
switch m {
default:
return false
case Options:
return true
case Head:
return true
case Post:
return true
case Get:
return true
case Put:
return true
case Patch:
return true
case Delete:
return true
case Connect:
return true
case Trace:
return true
}
}
// GetMethodName returns the upper-cased method, i.e. GET for a given method
// int value
func GetMethodName(m int) string {
switch m {
default:
return ""
case Options:
return "OPTIONS"
case Head:
return "HEAD"
case Post:
return "POST"
case Get:
return "GET"
case Put:
return "PUT"
case Patch:
return "PATCH"
case Delete:
return "DELETE"
case Connect:
return "CONNECT"
case Trace:
return "TRACE"
}
}
// GetMethodID returns an int value for a valid HTTP method name (upper-cased)
func GetMethodID(method string) int {
switch method {
default:
return 0
case "OPTIONS":
return Options
case "HEAD":
return Head
case "POST":
return Post
case "GET":
return Get
case "PUT":
return Put
case "PATCH":
return Patch
case "DELETE":
return Delete
case "CONNECT":
return Connect
case "TRACE":
return Trace
}
}
// GetHTTPMethod returns the method ID for the method in a HTTP request
func GetHTTPMethod(req *http.Request) int {
return GetMethodID(req.Method)
}