generated from pkg/go-template
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/service"
|
|
"git.icechen.cn/monorepo/backend/pkg/api"
|
|
"github.com/gofiber/fiber/v2"
|
|
ctxLogger "github.com/luizsuper/ctxLoggers"
|
|
"github.com/pkg/errors"
|
|
"go.uber.org/zap"
|
|
"strconv"
|
|
)
|
|
|
|
var (
|
|
idIsNotInt = api.WarpFError(errors.New("类型不是int"))
|
|
illegalInt = api.WarpFError(errors.New("非法类型"))
|
|
codeIsNull = api.WarpFError(errors.New("传入code为空"))
|
|
)
|
|
|
|
func Login(ctx *fiber.Ctx) error {
|
|
code := ctx.Query("code", "")
|
|
|
|
if code == "" {
|
|
ctxLogger.Error(ctx, codeIsNull.Error())
|
|
return codeIsNull
|
|
}
|
|
|
|
appType := ctx.Query("type", "")
|
|
|
|
l, err := strconv.Atoi(appType)
|
|
|
|
if err != nil {
|
|
ctxLogger.Error(ctx, idIsNotInt.Error(), zap.String("appType is ", appType))
|
|
return idIsNotInt
|
|
}
|
|
//目前暂定的appId
|
|
err = validate.Var(l, "oneof=1 2 3")
|
|
if err != nil {
|
|
ctxLogger.Error(ctx, illegalInt.Error(), zap.String("appType is ", appType))
|
|
return illegalInt
|
|
}
|
|
|
|
err = service.Login(ctx.UserContext(), code, appType)
|
|
|
|
if err != nil {
|
|
ctxLogger.Error(ctx, "login err", zap.String("reason", err.Error()))
|
|
return err
|
|
}
|
|
|
|
return ctx.JSON(success(nil))
|
|
}
|