Skip to content

Commit af5b96e

Browse files
committed
添加转换字符串method到Method类型
1 parent 6aabde5 commit af5b96e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

http/server/common.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/http"
7+
"strings"
78
)
89

910
//VariablePostion 变量位置.
@@ -51,6 +52,22 @@ const (
5152
RESTful
5253
)
5354

55+
//NewMethod 转换字符串method到Method类型.
56+
func NewMethod(m string) Method {
57+
switch strings.ToUpper(m) {
58+
case http.MethodGet:
59+
return GET
60+
case http.MethodPost:
61+
return POST
62+
case http.MethodPut:
63+
return PUT
64+
case http.MethodDelete:
65+
return DELETE
66+
67+
}
68+
return RESTful
69+
}
70+
5471
//String 类型转字符串
5572
func (m Method) String() string {
5673
switch m {

0 commit comments

Comments
 (0)