Skip to content

Commit

Permalink
Merge pull request #99 from karldoenitz/feature-v2.0.0
Browse files Browse the repository at this point in the history
Feature v2.0.0
  • Loading branch information
karldoenitz authored Oct 13, 2023
2 parents b3c1221 + 3d29a3f commit 560be14
Show file tree
Hide file tree
Showing 3 changed files with 56 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
26 changes: 26 additions & 0 deletions test_case/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package test_case

import (
"Tigo/TigoWeb"
"testing"
)

func TestEncryptDecrypt(t *testing.T) {
originData := "test data"
key := "key"
encryptData, err := TigoWeb.Encrypt([]byte(originData), []byte(key))
if err != nil {
t.Error(err.Error())
return
}
decryptData, err := TigoWeb.Decrypt([]byte(encryptData), []byte(key))
if err != nil {
t.Error(err.Error())
return
}
if string(decryptData) != originData {
t.Error("data invalid")
return
}
t.Log("success")
}

0 comments on commit 560be14

Please sign in to comment.