-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http-method.go
53 lines (49 loc) · 1.18 KB
/
http-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
package navaros
import (
"errors"
"strings"
)
// HTTPMethod represents an HTTP method.
type HTTPMethod string
const (
// All represents all HTTP methods.
All HTTPMethod = "ALL"
// Post represents the HTTP POST method.
Post HTTPMethod = "POST"
// Get represents the HTTP GET method.
Get HTTPMethod = "GET"
// Put represents the HTTP PUT method.
Put HTTPMethod = "PUT"
// Patch represents the HTTP PATCH method.
Patch HTTPMethod = "PATCH"
// Delete represents the HTTP DELETE method.
Delete HTTPMethod = "DELETE"
// Options represents the HTTP OPTIONS method.
Options HTTPMethod = "OPTIONS"
// Head represents the HTTP HEAD method.
Head HTTPMethod = "HEAD"
)
// HTTPMethodFromString converts a string to an HTTPMethod.
// If the string is not a valid HTTP method, an error is returned.
func HTTPMethodFromString(method string) HTTPMethod {
switch strings.ToUpper(method) {
case "ALL", "*":
return All
case "POST":
return Post
case "GET":
return Get
case "PUT":
return Put
case "PATCH":
return Patch
case "DELETE":
return Delete
case "OPTIONS":
return Options
case "HEAD":
return Head
default:
panic(errors.New("invalid http method `" + method + "`"))
}
}