49 lines
1.1 KiB
Go
49 lines
1.1 KiB
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) (TestOut, error) {
|
|
return TestOut{
|
|
FormData: formData,
|
|
}, nil
|
|
}
|
|
|
|
type TestOut struct {
|
|
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"`
|
|
FormData *TestForm `json:"form_data" form:"form_data"`
|
|
}
|
|
|
|
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")
|
|
s := NewServer(8888, nil)
|
|
s.Group("test", nil, TestController{})
|
|
s.Start()
|
|
}
|