You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.2 KiB

/**
* Copyright (C) 2020-2021
* All rights reserved, Designed By www.yixiang.co
* 注意本软件为www.yixiang.co开发研制
*/
package controllers
import (
beego "github.com/beego/beego/v2/server/web"
"yixiang.co/yshop/dto"
)
type BaseController struct {
beego.Controller
}
func (c *BaseController) GetParams() dto.BasePage {
var (
page int
size int
blurry string
)
c.Ctx.Input.Bind(&page, "page")
c.Ctx.Input.Bind(&size, "size")
c.Ctx.Input.Bind(&blurry, "blurry")
return dto.BasePage{Page: page,Size: size,Blurry: blurry}
}
type any = interface {}
type Result struct {
Data interface{} `json:"data"`
Msg string `json:"msg"`
Status int `json:"status"`
}
func ErrMsg(msg string,status ...int) Result {
var r Result
if len(status) > 0 {
r.Status = status[0]
}else{
r.Status = 500000
}
r.Msg = msg
r.Data = nil
return r
}
func ErrData(msg error,status ...int) Result {
var r Result
if len(status) > 0 {
r.Status = status[0]
} else {
r.Status = 500000
}
r.Msg = msg.Error()
r.Data = nil
return r
}
func SuccessData(data any) Result {
var r Result
r.Status = 200
r.Msg = "ok"
r.Data = data
return r
}