generated from pkg/go-template
@@ -9,7 +9,7 @@ import (
|
||||
"git.icechen.cn/monorepo/backend/pkg/api"
|
||||
"git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders"
|
||||
"git.icechen.cn/monorepo/backend/pkg/rpc"
|
||||
"github.com/go-playground/validator/v10"
|
||||
validator "github.com/go-playground/validator/v10"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
ctxLogger "github.com/luizsuper/ctxLoggers"
|
||||
"github.com/pkg/errors"
|
||||
@@ -21,8 +21,13 @@ import (
|
||||
var (
|
||||
pageIsNotInt = api.WarpFError(errors.New("page 参数错误"))
|
||||
limitIsNotInt = api.WarpFError(errors.New("limit 参数错误"))
|
||||
validate *validator.Validate
|
||||
)
|
||||
|
||||
func init() {
|
||||
validate = validator.New()
|
||||
}
|
||||
|
||||
func GetScriptsH(ctx *fiber.Ctx) error {
|
||||
page := ctx.Query("page", "1")
|
||||
limit := ctx.Query("size", "10")
|
||||
@@ -110,8 +115,6 @@ func GetScriptApi(ctx *fiber.Ctx) error {
|
||||
return pageIsNotInt
|
||||
}
|
||||
|
||||
validate := validator.New()
|
||||
|
||||
err = validate.Var(p, "gte=0")
|
||||
if err != nil {
|
||||
ctxLogger.Error(ctx.UserContext(), limitIsNotInt.Error(), zap.String("limit", limit))
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
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))
|
||||
}
|
||||
Reference in New Issue
Block a user