u
This commit is contained in:
1 parent
9af3234672
commit
ed8bee3d77
11 files changed
+171
-57
No files matched your search
@@ -0,0 +1,31 @@
|
||||
package handle
|
||||
|
||||
import "base-framework/pkg/router"
|
||||
|
||||
func Login(c *router.Context) {
|
||||
// 直接用 BindJSON 绑定请求体 JSON 到结构体
|
||||
var req struct {
|
||||
OrgID string `json:"orgID"`
|
||||
UserID string `json:"userID"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(400, map[string]string{"error": "请求体格式错误"})
|
||||
return
|
||||
}
|
||||
|
||||
// 模拟校验
|
||||
if req.UserID == "" || req.Password == "" {
|
||||
c.JSON(400, map[string]string{"error": "账号或密码不能为空"})
|
||||
return
|
||||
}
|
||||
|
||||
// 登录成功,返回 token 示例
|
||||
c.JSON(200, map[string]interface{}{
|
||||
"code": "0000",
|
||||
"message": "登录成功",
|
||||
"data": map[string]string{
|
||||
"token": "这里是token字符串",
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user