-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTTPMethodType.go
82 lines (74 loc) · 1.75 KB
/
HTTPMethodType.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
package request
import "strings"
// HTTPMethodType is the type of a method request
type HTTPMethodType int
const (
// HTTPMethodUnknown is an unknown method type
HTTPMethodUnknown HTTPMethodType = iota
// HTTPMethodGet is the http method 'GET'
HTTPMethodGet
// HTTPMethodPost is the http method POST
HTTPMethodPost
// HTTPMethodPut is the http method PUT
HTTPMethodPut
// HTTPMethodDelete is the http method DELETE
HTTPMethodDelete
// HTTPMethodOptions is the http method OPTIONS
HTTPMethodOptions
// HTTPMethodHead is the http method HEAD
HTTPMethodHead
// HTTPMethodTrace is the http method TRACE
HTTPMethodTrace
// HTTPMethodPatch is the http method PATCH
HTTPMethodPatch
)
// HTTPMethodTypeFromString converts a method from a string to its method type
func HTTPMethodTypeFromString(method string) HTTPMethodType {
method = strings.ToLower(method)
switch method {
case "get":
return HTTPMethodGet
case "post":
return HTTPMethodPost
case "put":
return HTTPMethodPut
case "delete":
return HTTPMethodDelete
case "options":
return HTTPMethodOptions
case "head":
return HTTPMethodHead
case "trace":
return HTTPMethodTrace
case "patch":
return HTTPMethodPatch
default:
return HTTPMethodUnknown
}
}
func HTTPMethodTypeToString(t HTTPMethodType) string {
switch t {
case HTTPMethodGet:
return "GET"
case HTTPMethodPost:
return "POST"
case HTTPMethodPut:
return "PUT"
case HTTPMethodDelete:
return "DELETE"
case HTTPMethodOptions:
return "OPTIONS"
case HTTPMethodHead:
return "HEAD"
case HTTPMethodTrace:
return "TRACE"
case HTTPMethodPatch:
return "PATCH"
default:
return "UNKNOWN"
}
}
// Int64 returns the int64 representation of the HTTPMethodType value
func (h HTTPMethodType) Int64() int64 {
return int64(h)
}