diff --git a/client/micro-mall-api_test.go b/client/micro-mall-api_test.go index fb26b0462d653225de5887243c5f3208e8ac30d9..3aa302b532a280ca2831a8b7401c80a7a66343fa 100644 --- a/client/micro-mall-api_test.go +++ b/client/micro-mall-api_test.go @@ -16,6 +16,9 @@ import ( ) func TestGateway(t *testing.T) { + t.Run("ping",TestPing) + t.Run("debug Compression",TestDebugCompression) + t.Run("debug no-Compression",TestDebugNoCompression) t.Run("发送验证码", TestVerifyCodeSend) t.Run("注册用户", TestRegisterUser) t.Run("登录用户-验证码", TestLoginUserWithVerifyCode) @@ -57,6 +60,55 @@ func BenchmarkGateway(b *testing.B) { b.Run("批量创建订单并支付-用户3", BenchmarkTestOrderTrade_3) } +func TestPing(t *testing.T) { + r := baseUrlHost + ping + t.Logf("request url: %s", r) + req, err := http.NewRequest("GET", r, nil) + if err != nil { + t.Error(err) + return + } + commonTest(r, req, t) +} + +func TestDebugCompression(t *testing.T) { + r := baseUrlHost + debugCompression + t.Logf("request url: %s", r) + req, err := http.NewRequest("GET", r, nil) + if err != nil { + t.Error(err) + return + } + analysisCompression(r, req, t) +} + +func TestDebugNoCompression(t *testing.T) { + r := baseUrlHost + debugNoCompression + t.Logf("request url: %s", r) + req, err := http.NewRequest("GET", r, nil) + if err != nil { + t.Error(err) + return + } + analysisCompression(r, req, t) +} + +func analysisCompression(r string,req *http.Request,t *testing.T) { + t.Logf("request token=%v", qToken) + rsp, err := http.DefaultClient.Do(req) + if err != nil { + t.Error(err) + return + } + t.Logf("req url: %v status : %v", r, rsp.Status) + if rsp.StatusCode != http.StatusOK { + t.Error("StatusCode != 200") + return + } + + t.Logf("rsp header:%v\n",rsp.Header) +} + func TestGetUserInfo(t *testing.T) { r := baseUrl + userInfo t.Logf("request url: %s", r) @@ -188,7 +240,7 @@ func TestOrderTradePay(t *testing.T) { r := baseUrl + tradeOrderPay t.Logf("request url: %s", r) data := url.Values{} - data.Set("tx_code", "544cebd5-cf16-4c5c-a9b1-77f3835fcee7") + data.Set("tx_code", "583e920e-17fd-486a-b48e-5c1187d00d44") t.Logf("req data: %v", data) req, err := http.NewRequest("POST", r, strings.NewReader(data.Encode())) if err != nil { diff --git a/client/url.go b/client/url.go index 43ce0a4b6201d5c72eb29056f6c938971f9f3af4..8ca47d436fb06be028a24e848d805b7987eecc39 100644 --- a/client/url.go +++ b/client/url.go @@ -4,10 +4,14 @@ const ( baseUrlProd = "https://xxx.xxx.xx/api" baseUrlTestAli = "http://xx.xx.xx.xx:xxx/api" baseUrlDev = "http://xx.xx.xx.56:xx/api" + baseUrlHost = "http://localhost:52001" baseUrlLocal = "http://localhost:52001/api" ) const ( + ping = "/ping" + debugCompression = "/debug/compression" + debugNoCompression = "/debug/no-compression" verifyCodeSend = "/verify_code/send" registerUser = "/register" loginUserWithVerifyCode = "/login/verify_code" diff --git a/etc/app.ini b/etc/app.ini index 0d756ccaf98fad52ee7addce261e26069d365a38..7d44d0e8e166d95c590b9048cdcfcc05d8db797c 100644 --- a/etc/app.ini +++ b/etc/app.ini @@ -32,32 +32,8 @@ Password = "07030501310" DB = 1 PoolNum = 10 -;[queue-user-register-notice] -;Broker = "amqp://micro-mall:szJ9aePR@localhost:5672/micro-mall" -;DefaultQueue = "user_register_notice" -;ResultBackend = "redis://07030501310@127.0.0.1:6379/8" -;ResultsExpireIn = 3600 -;Exchange = "user_register_notice" -;ExchangeType = "direct" -;BindingKey = "user_register_notice" -;PrefetchCount = 5 -;TaskRetryCount = 3 -;TaskRetryTimeout = 3600 -; -;[queue-user-state-notice] -;Broker = "amqp://micro-mall:szJ9aePR@localhost:5672/micro-mall" -;DefaultQueue = "user_state_notice" -;ResultBackend = "redis://07030501310@127.0.0.1:6379/8" -;ResultsExpireIn = 3600 -;Exchange = "user_state_notice" -;ExchangeType = "direct" -;BindingKey = "user_state_notice" -;PrefetchCount = 5 -;TaskRetryCount = 3 -;TaskRetryTimeout = 3600 - [email-config] -User = "1225807604@qq.com" -Password = "vyuuwxudvazshcid" +User = "xxx@qq.com" +Password = "xxx" Host = "smtp.qq.com" Port = "465" \ No newline at end of file diff --git a/go.mod b/go.mod index cdfd4d25da79985cb57280c319e8fbc259258173..00e13241f97e5038da581df54791771a2c55723c 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/astaxie/beego v1.12.2 github.com/cosmtrek/air v1.21.2 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible + github.com/gin-contrib/gzip v0.0.3 github.com/gin-gonic/gin v1.6.3 github.com/go-ini/ini v1.60.2 github.com/go-sql-driver/mysql v1.5.0 diff --git a/go.sum b/go.sum index 141f4c7755028d84dfb32ae6363cb2cc8a367b0d..393b52adc26dc64434949ba0e64f6bc126fb4015 100644 --- a/go.sum +++ b/go.sum @@ -182,6 +182,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gin-contrib/gzip v0.0.3 h1:etUaeesHhEORpZMp18zoOhepboiWnFtXrBZxszWUn4k= +github.com/gin-contrib/gzip v0.0.3/go.mod h1:YxxswVZIqOvcHEQpsSn+QF5guQtO1dCfy0shBPy4jFc= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= diff --git a/model/args/form.go b/model/args/form.go index dae0e93ca36ff01a9bc0750748075051e2bccd16..3cdf5f4d25b15162f68be650143dea33d5054700 100644 --- a/model/args/form.go +++ b/model/args/form.go @@ -6,6 +6,10 @@ import ( "strconv" ) +type DebugCompressionRsp struct { + Time []string `json:"time"` +} + type UserAccountChargeArgs struct { Uid int `json:"uid"` Ip string `json:"ip"` diff --git a/router/api/v1/index.go b/router/api/v1/index.go index 802bf8b71570caebc4da1fdd5b867cfbaa79538c..88d60bdc9afb2e5b1d19e3b2fd3013ae8b89c928 100644 --- a/router/api/v1/index.go +++ b/router/api/v1/index.go @@ -1,11 +1,14 @@ package v1 import ( + "gitee.com/cristiane/micro-mall-api/model/args" "gitee.com/cristiane/micro-mall-api/pkg/app" "gitee.com/cristiane/micro-mall-api/pkg/code" "gitee.com/cristiane/micro-mall-api/vars" "github.com/gin-gonic/gin" + "math" "net/http" + "strconv" "time" ) @@ -17,3 +20,14 @@ func IndexApi(c *gin.Context) { func PingApi(c *gin.Context) { app.JsonResponse(c, http.StatusOK, code.SUCCESS, time.Now()) } + +func DebugCompressionApi(c *gin.Context) { + n := math.MaxInt16 + rsp := &args.DebugCompressionRsp{ + Time: make([]string, n), + } + for i := 0; i < n; i++ { + rsp.Time[i] = strconv.Itoa(int(time.Now().UnixNano())) + } + app.JsonResponse(c, http.StatusOK, code.SUCCESS, rsp) +} diff --git a/router/router.go b/router/router.go index 3014e38ece977d49ca98f296c5fe7eb374629c2c..bc6da8f0df9026f54683bd5a5e785c9d6c4b6134 100644 --- a/router/router.go +++ b/router/router.go @@ -4,6 +4,7 @@ import ( "gitee.com/cristiane/micro-mall-api/middleware" v1 "gitee.com/cristiane/micro-mall-api/router/api/v1" "gitee.com/cristiane/micro-mall-api/vars" + "github.com/gin-contrib/gzip" "io" "os" @@ -21,9 +22,15 @@ func InitRouter(accessInfoLogger, accessErrLogger io.Writer) *gin.Engine { } r := gin.Default() + r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedPaths([]string{ + "/static/", + "/debug/no-compression", + }))) r.Use(middleware.Cors()) r.GET("/", v1.IndexApi) - r.GET("/ping", v1.PingApi) // ping + r.GET("/ping", v1.PingApi) + r.GET("/debug/compression", v1.DebugCompressionApi) + r.GET("/debug/no-compression", v1.DebugCompressionApi) r.Static("/static", "./static") apiG := r.Group("/api") apiV1 := apiG.Group("/v1")