DI&GIN验证尝试

DI 框架我是没招了,GO 的狗屎接口系统让运行时的DI注入都没办法自动收集接口。
所以...只能捏着鼻子用了。正在想办法解决 GIN 验证框架返回英文的问题
This commit is contained in:
des
2026-01-23 00:02:13 +08:00
parent 688177ba06
commit 731f1d01e6
12 changed files with 157 additions and 132 deletions

View File

@@ -3,6 +3,7 @@ package userpak
import (
"Crimson-Gatekeeper/internal/query"
"fmt"
"net/http"
"github.com/gin-gonic/gin"
)
@@ -17,8 +18,14 @@ func NewUserCtl(q *query.Query) *UserCtl {
func (u *UserCtl) login(ctx *gin.Context) {
lp := loginParam{}
err := ctx.ShouldBindBodyWithJSON(&lp)
err := ctx.ShouldBindQuery(&lp)
if err != nil {
fmt.Println("出错啦")
fmt.Println(err)
}
ctx.JSON(http.StatusOK, lp)
}
func (u *UserCtl) RegisterRoutes(eng *gin.Engine) {
eng.GET("/login", u.login)
}

View File

@@ -1,6 +1,6 @@
package userpak
type loginParam struct {
Account string `json:"account"`
Password string `json:"password"`
Account string `json:"account" binding:"required"`
Password string `json:"password" binding:"required"`
}