DI&GIN验证尝试
DI 框架我是没招了,GO 的狗屎接口系统让运行时的DI注入都没办法自动收集接口。 所以...只能捏着鼻子用了。正在想办法解决 GIN 验证框架返回英文的问题
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user