Skip to content

Commit

Permalink
添加转换字符串method到Method类型
Browse files Browse the repository at this point in the history
  • Loading branch information
c-wind committed Jan 3, 2018
1 parent 6aabde5 commit af5b96e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions http/server/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"
)

//VariablePostion 变量位置.
Expand Down Expand Up @@ -51,6 +52,22 @@ const (
RESTful
)

//NewMethod 转换字符串method到Method类型.
func NewMethod(m string) Method {
switch strings.ToUpper(m) {
case http.MethodGet:
return GET
case http.MethodPost:
return POST
case http.MethodPut:
return PUT
case http.MethodDelete:
return DELETE

}
return RESTful
}

//String 类型转字符串
func (m Method) String() string {
switch m {
Expand Down

0 comments on commit af5b96e

Please sign in to comment.