Files
gin/router/server_test.go

42 lines
866 B
Go

// Package router ...
//
// Description : router ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-05-28 20:58
package router
import (
"testing"
"git.zhangdeman.cn/zhangdeman/rate_limit"
"github.com/gin-gonic/gin"
)
type testCommon struct {
UserID uint `json:"user_id"`
}
type testForm struct {
Meta `json:"-" method:"get" path:"test" rate-limit:"1/5/60"`
testCommon
Name string `json:"name"`
}
func TestNewServer(t *testing.T) {
s := NewServer(9087, WithRateLimitInstance(rate_limit.MemoryClient))
s.AddCommonParamRule("UserID", func(ctx *gin.Context) (any, error) {
return uint(123456), nil
})
s.Group("", nil, testController{})
s.Start()
}
type testController struct {
}
func (tc testController) Test(ctx *gin.Context, requestData *testForm) (*testCommon, error) {
return &testCommon{UserID: requestData.UserID}, nil
}