mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Basic check for User controller
This commit is contained in:
25
routers/controllers/main.go
Normal file
25
routers/controllers/main.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"Cloudreve/serializer"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gopkg.in/go-playground/validator.v8"
|
||||
)
|
||||
|
||||
// ErrorResponse 返回错误消息
|
||||
func ErrorResponse(err error) serializer.Response {
|
||||
if ve, ok := err.(validator.ValidationErrors); ok {
|
||||
for _, e := range ve {
|
||||
return serializer.ParamErr(
|
||||
fmt.Sprintf("%s %s", e.Field, e.Tag),
|
||||
err,
|
||||
)
|
||||
}
|
||||
}
|
||||
if _, ok := err.(*json.UnmarshalTypeError); ok {
|
||||
return serializer.ParamErr("JSON类型不匹配", err)
|
||||
}
|
||||
|
||||
return serializer.ParamErr("参数错误", err)
|
||||
}
|
||||
22
routers/controllers/user.go
Normal file
22
routers/controllers/user.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"Cloudreve/serializer"
|
||||
"Cloudreve/service/user"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// UserLogin 用户登录
|
||||
func UserLogin(c *gin.Context) {
|
||||
var service service.UserLoginService
|
||||
if err := c.ShouldBindJSON(&service); err == nil {
|
||||
//res := service.Login(c)
|
||||
c.JSON(200, serializer.Response{
|
||||
Code: 0,
|
||||
Msg: "OK",
|
||||
})
|
||||
} else {
|
||||
c.JSON(200, ErrorResponse(err))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,10 +8,13 @@ import (
|
||||
func InitRouter() *gin.Engine {
|
||||
r := gin.Default()
|
||||
|
||||
// 路由
|
||||
// 顶层路由分组
|
||||
v3 := r.Group("/Api/V3")
|
||||
{
|
||||
// 测试用路由
|
||||
v3.GET("Ping", controllers.Ping)
|
||||
// 用户登录
|
||||
v3.POST("User/Login", controllers.UserLogin)
|
||||
|
||||
}
|
||||
return r
|
||||
|
||||
Reference in New Issue
Block a user