gin/router/register_test.go

39 lines
834 B
Go

// Package router ...
//
// Description : router ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-07-20 23:24
package router
import (
"testing"
"github.com/gin-gonic/gin"
)
type TestController struct{}
func (t TestController) Logic(ctx *gin.Context, formData *TestForm) (any, error) {
return formData, nil
}
type TestForm struct {
Meta `tag:"测试表单" path:"/a/b/c/d" desc:"测试接口" method:"get"`
Age int `json:"age" form:"age" binding:"min=20" err_msg:"年龄不能小于20"`
Name string `json:"name" form:"name"`
Test *Test `json:"test" form:"test"`
Num *int64 `json:"num" form:"num"`
}
type Test struct {
L string `json:"l"`
}
func Test_parseController(t *testing.T) {
SetValidateErrTag("err_msg")
r := gin.Default()
Group(r, "test", nil, TestController{})
r.Run(":8080")
}