Skip to content

Commit

Permalink
修改method枚举
Browse files Browse the repository at this point in the history
  • Loading branch information
karldoenitz committed Oct 13, 2023
1 parent 4953f83 commit 3d29a3f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
44 changes: 24 additions & 20 deletions TigoWeb/enums.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package TigoWeb

// MethodMapping http请求方式的一个映射
var MethodMapping = map[string]string{
"get": "Get",
"head": "Head",
"post": "Post",
"put": "Put",
"delete": "Delete",
"connect": "Connect",
"options": "Options",
"trace": "Trace",
"GET": "Get",
"HEAD": "Head",
"POST": "Post",
"PUT": "Put",
"DELETE": "Delete",
"CONNECT": "Connect",
"OPTIONS": "Options",
"TRACE": "Trace",
}

const Version = "1.6.5"

// MethodEnum 根据http请求方式获取对应的函数名
// - httpMethod: http请求方式
func MethodEnum(httpMethod string) string {
var MethodMapping = map[string]string{
"get": "Get",
"head": "Head",
"post": "Post",
"put": "Put",
"delete": "Delete",
"connect": "Connect",
"options": "Options",
"trace": "Trace",
"GET": "Get",
"HEAD": "Head",
"POST": "Post",
"PUT": "Put",
"DELETE": "Delete",
"CONNECT": "Connect",
"OPTIONS": "Options",
"TRACE": "Trace",
}
return MethodMapping[httpMethod]
}
12 changes: 6 additions & 6 deletions TigoWeb/urlpattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ type UrlPatternHandle struct {
}

// Handle 封装HTTP请求的中间件,主要有以下功能:
// - 1、根据反射找到挂载的handler;
// - 2、调用handler的InitHandler方法;
// - 3、进行HTTP请求预处理,包括判断请求方式是否合法等;
// - 4、调用handler中的功能方法;
// - 5、进行HTTP请求结束处理。
// - 1、根据反射找到挂载的handler;
// - 2、调用handler的InitHandler方法;
// - 3、进行HTTP请求预处理,包括判断请求方式是否合法等;
// - 4、调用handler中的功能方法;
// - 5、进行HTTP请求结束处理。
func (urlPatternMidWare UrlPatternHandle) Handle(responseWriter http.ResponseWriter, request *http.Request) {
handlerType := reflect.TypeOf(urlPatternMidWare.Handler)
if handlerType.Kind() == reflect.Ptr {
Expand All @@ -41,7 +41,7 @@ func (urlPatternMidWare UrlPatternHandle) Handle(responseWriter http.ResponseWri
// 调用BeforeRequest方法
VoidFuncCall(handler, FnBeforeRequest)
// 根据http请求方式调用相关方法
VoidFuncCall(handler, MethodMapping[request.Method])
VoidFuncCall(handler, MethodEnum(request.Method))
// 调用TeardownRequest方法
VoidFuncCall(handler, FnTeardownRequest)
}
Expand Down

0 comments on commit 3d29a3f

Please sign in to comment.