cool

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2022 License: MIT Imports: 20 Imported by: 29

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GromDBS MGromDBS // 定义全局gorm.DB对象集合
	// CacheEPS *gcache.Cache // 定义全局缓存对象	供EPS使用
	CacheEPS = gcache.New() // 定义全局缓存对象	供EPS使用
	Cache    = gcache.New() // 定义全局缓存对象	供其他业务使用
)

Functions

func CreateTable

func CreateTable(model IModel) error

根据entity结构体创建表

func FillInitData

func FillInitData(moduleName string, model IModel) error

数据库填充初始数据

func GDBModel

func GDBModel(m IModel) *gdb.Model

GDBModel 数据库连接

func GVartoType

func GVartoType(GVar *g.Var, wantType string) interface{}

转换gVar值类型

func GetDBbyModel

func GetDBbyModel(model IModel) *gorm.DB

根据entity结构体获取DB

func MiddlewareHandlerResponse

func MiddlewareHandlerResponse(r *ghttp.Request)

MiddlewareHandlerResponse is the default middleware handling handler response object and its error.

func RegisterController

func RegisterController(c IController)

注册控制器到路由

func RegisterControllerSimple

func RegisterControllerSimple(perfix string, controller IControllerSimple)

注册不带crud的路由

Types

type AddReq

type AddReq struct {
	g.Meta `path:"/add" method:"POST"`
}

type Admin

type Admin struct {
	IsRefresh       bool   `json:"isRefresh"`
	RoleIds         []int  `json:"roleIds"`
	Username        string `json:"username"`
	UserId          uint   `json:"userId"`
	PasswordVersion *int32 `json:"passwordVersion"`
}

func GetAdmin

func GetAdmin(ctx context.Context) *Admin

获取传入ctx 中的 admin 对象

type BaseRes

type BaseRes struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

cool.OK 正常返回

func Ok

func Ok(data interface{}) *BaseRes

返回正常结果

type Controller

type Controller struct {
	Perfix  string     `json:"perfix"`
	Api     g.ArrayStr `json:"api"`
	Service IService   `json:"service"`
}

func (*Controller) Add

func (c *Controller) Add(ctx context.Context, req *AddReq) (res *BaseRes, err error)

func (*Controller) Delete

func (c *Controller) Delete(ctx context.Context, req *DeleteReq) (res *BaseRes, err error)

func (*Controller) Info

func (c *Controller) Info(ctx context.Context, req *InfoReq) (res *BaseRes, err error)

func (*Controller) List

func (c *Controller) List(ctx context.Context, req *ListReq) (res *BaseRes, err error)

func (*Controller) Page

func (c *Controller) Page(ctx context.Context, req *PageReq) (res *BaseRes, err error)

func (*Controller) Update

func (c *Controller) Update(ctx context.Context, req *UpdateReq) (res *BaseRes, err error)

type ControllerSimple

type ControllerSimple struct {
	Perfix string
}

type DefaultHandlerResponse

type DefaultHandlerResponse struct {
	Code    int         `json:"code"    dc:"Error code"`
	Message string      `json:"message" dc:"Error message"`
	Data    interface{} `json:"data,omitempty"    dc:"Result data for certain request according API definition"`
}

DefaultHandlerResponse is the default implementation of HandlerResponse.

type DeleteReq

type DeleteReq struct {
	g.Meta `path:"/delete" method:"POST"`
	Ids    []int `json:"ids" v:"required#请选择要删除的数据"`
}

type IController

type IController interface {
	Add(ctx context.Context, req *AddReq) (res *BaseRes, err error)
	Delete(ctx context.Context, req *DeleteReq) (res *BaseRes, err error)
	Update(ctx context.Context, req *UpdateReq) (res *BaseRes, err error)
	Info(ctx context.Context, req *InfoReq) (res *BaseRes, err error)
	List(ctx context.Context, req *ListReq) (res *BaseRes, err error)
	Page(ctx context.Context, req *PageReq) (res *BaseRes, err error)
}

type IControllerSimple

type IControllerSimple interface {
}

type IModel

type IModel interface {
	TableName() string
	GroupName() string
}

type IService

type IService interface {
	ServiceAdd(ctx context.Context, req *AddReq) (data interface{}, err error)
	ServiceDelete(ctx context.Context, req *DeleteReq) (data interface{}, err error)
	ServiceUpdate(ctx context.Context, req *UpdateReq) (data interface{}, err error)
	ServiceInfo(ctx context.Context, req *InfoReq) (data interface{}, err error)
	ServiceList(ctx context.Context, req *ListReq) (data interface{}, err error)
	ServicePage(ctx context.Context, req *PageReq) (data interface{}, err error)
}

type InfoReq

type InfoReq struct {
	g.Meta `path:"/info" method:"GET"`
	ID     int `json:"id" v:"integer|required#请选择要查询的数据"`
}

type InfoRes

type InfoRes struct {
	*BaseRes
	Data interface{} `json:"data"`
}

type ListQueryOp

type ListQueryOp struct {
	FieldEQ      []string    // 字段等于
	KeyWorkField []string    // 模糊搜索匹配的数据库字段
	AddOrderby   g.MapStrStr // 添加排序
}

List接口条件配置

type ListReq

type ListReq struct {
	g.Meta `path:"/list" method:"POST"`
	Order  string `json:"order"`
	Sort   string `json:"sort"`
}

type MGromDBS

type MGromDBS map[string]*gorm.DB

type Model

type Model struct {
	ID         uint           `gorm:"primaryKey" json:"id"`
	CreateTime *time.Time     `gorm:"column:createTime;not null;index,priority:1;autoCreateTime:nano;comment:创建时间" json:"createTime"` // 创建时间
	UpdateTime *time.Time     `gorm:"column:updateTime;not null;index,priority:1;autoUpdateTime:nano;comment:更新时间" json:"updateTime"` // 更新时间
	DeletedAt  gorm.DeletedAt `gorm:"index" json:"deletedAt"`
}

func NewModel

func NewModel() *Model

func (*Model) GroupName

func (m *Model) GroupName() string

返回分组名

func (*Model) TableName

func (m *Model) TableName() string

返回表名

type PageReq

type PageReq struct {
	g.Meta `path:"/page" method:"POST"`
	Page   int `d:"1" json:"page"`
	Size   int `d:"15" json:"size"`
}

type Service

type Service struct {
	Model       IModel
	ListQueryOp *ListQueryOp
}

func NewService

func NewService(model IModel) *Service

func (*Service) ServiceAdd

func (s *Service) ServiceAdd(ctx context.Context, req *AddReq) (data interface{}, err error)

func (*Service) ServiceDelete

func (s *Service) ServiceDelete(ctx context.Context, req *DeleteReq) (data interface{}, err error)

func (*Service) ServiceInfo

func (s *Service) ServiceInfo(ctx context.Context, req *InfoReq) (data interface{}, err error)

func (*Service) ServiceList

func (s *Service) ServiceList(ctx context.Context, req *ListReq) (data interface{}, err error)

func (*Service) ServicePage

func (s *Service) ServicePage(ctx context.Context, req *PageReq) (data interface{}, err error)

func (*Service) ServiceUpdate

func (s *Service) ServiceUpdate(ctx context.Context, req *UpdateReq) (data interface{}, err error)

type UpdateReq

type UpdateReq struct {
	g.Meta `path:"/update" method:"POST"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL