cool

package module
v1.5.10 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: MIT Imports: 24 Imported by: 29

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Config            = coolconfig.Config            // 配置中的cool节相关配置
	GetCfgWithDefault = coolconfig.GetCfgWithDefault // GetCfgWithDefault 获取配置,如果配置不存在,则使用默认值
)
View Source
var (
	GormDBS      = make(map[string]*gorm.DB) // 定义全局gorm.DB对象集合 仅供内部使用
	CacheEPS     = gcache.New()              // 定义全局缓存对象	供EPS使用
	CacheManager = gcache.New()              // 定义全局缓存对象	供其他业务使用
	ProcessFlag  = guid.S()                  // 定义全局进程标识
	RunMode      = "dev"                     // 定义全局运行模式
	IsRedisMode  = false                     // 定义全局是否为redis模式
	I18n         = gi18n.New()               // 定义全局国际化对象
)
View Source
var (
	File = coolfile.NewFile // File 文件上传操作
)
View Source
var FuncMap = make(map[string]CoolFunc)

FuncMap 函数列表

View Source
var ModelInfo = make(map[string][]*ColumnInfo)

ModelInfo 路由prefix 对应的model信息

Functions

func ClusterRunFunc added in v0.2.1

func ClusterRunFunc(ctx g.Ctx, funcstring string) (err error)

ClusterRunFunc 集群运行函数,如果是单机模式, 则直接运行函数

func CreateTable

func CreateTable(model IModel) error

根据entity结构体创建表

func DBM added in v0.0.23

func DBM(m IModel) *gdb.Model

DBM 根据model获取 *gdb.Model

func FillInitData

func FillInitData(ctx g.Ctx, moduleName string, model IModel) error

FillInitData 数据库填充初始数据

func GDBM added in v0.0.17

func GDBM(m IModel) *gdb.Model

Deprecated 请使用 cool.DBM 替代

func InitDB added in v0.0.21

func InitDB(group string) (*gorm.DB, error)

初始化数据库连接供gorm使用

func ListenFunc added in v0.2.1

func ListenFunc(ctx g.Ctx)

ListenFunc 监听函数

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(c IControllerSimple)

注册不带crud的路由

func RegisterFunc added in v0.2.1

func RegisterFunc(name string, f CoolFunc)

RegisterFunc 注册函数

func RunFunc added in v0.2.1

func RunFunc(ctx g.Ctx, funcstring string) (err error)

RunFunc 运行函数

Types

type AddReq

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

type Admin

type Admin struct {
	IsRefresh       bool     `json:"isRefresh"`
	RoleIds         []string `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 Fail added in v0.0.17

func Fail(message string) *BaseRes

失败返回结果

func Ok

func Ok(data interface{}) *BaseRes

返回正常结果

type Claims added in v1.5.2

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

type ColumnInfo added in v0.0.18

type ColumnInfo struct {
	Comment      string `json:"comment"`
	Length       string `json:"length"`
	Nullable     bool   `json:"nullable"`
	PropertyName string `json:"propertyName"`
	Type         string `json:"type"`
}

ColumnInfo 表字段信息

type Controller

type Controller struct {
	Prefix  string     `json:"prefix"`
	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 {
	Prefix string
}

type CoolFunc added in v0.2.1

type CoolFunc interface {
	// Func handler
	Func(ctx g.Ctx, param string) (err error)
	// IsSingleton 是否单例,当为true时,只能有一个任务在执行,在注意函数为计划任务时使用
	IsSingleton() bool
	// IsAllWorker 是否所有worker都执行
	IsAllWorker() bool
}

func GetFunc added in v0.2.1

func GetFunc(name string) CoolFunc

GetFunc 获取函数

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)     // 分页
	ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error)  // 新增|删除|修改前的操作
	ModifyAfter(ctx context.Context, method string, param g.MapStrAny) (err error)   // 新增|删除|修改后的操作
	GetModel() IModel                                                                // 获取model
}

type InfoReq

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

type JoinOp added in v0.0.18

type JoinOp struct {
	Model     IModel   // 关联的model
	Alias     string   // 别名
	Condition string   // 关联条件
	Type      JoinType // 关联类型  LeftJoin RightJoin InnerJoin
}

JoinOp 关联查询

type JoinType added in v0.0.18

type JoinType string

JoinType 关联类型

const (
	LeftJoin  JoinType = "LeftJoin"
	RightJoin JoinType = "RightJoin"
	InnerJoin JoinType = "InnerJoin"
)

Join 类型

type ListReq

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

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  time.Time `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"`    //每页条数
	Order          string `json:"order"`          // 排序字段
	Sort           string `json:"sort"`           // 排序方式 asc desc
	IsExport       bool   `json:"isExport"`       // 是否导出
	MaxExportLimit int    `json:"maxExportLimit"` // 最大导出条数,不传或者小于等于0则不限制
}

type QueryOp added in v0.0.18

type QueryOp struct {
	FieldEQ      []string                                      // 字段等于
	KeyWordField []string                                      // 模糊搜索匹配的数据库字段
	AddOrderby   g.MapStrStr                                   // 添加排序
	Where        func(ctx context.Context) []g.Array           // 自定义条件
	Select       string                                        // 查询字段,多个字段用逗号隔开 如: id,name  或  a.id,a.name,b.name AS bname
	Join         []*JoinOp                                     // 关联查询
	Extend       func(ctx g.Ctx, m *gdb.Model) *gdb.Model      // 追加其他条件
	ModifyResult func(ctx g.Ctx, data interface{}) interface{} // 修改结果
}

List/Add接口条件配置

type Service

type Service struct {
	Model              IModel
	ListQueryOp        *QueryOp
	PageQueryOp        *QueryOp
	InsertParam        func(ctx context.Context) g.MapStrAny // Add时插入参数
	Before             func(ctx context.Context) (err error) // CRUD前的操作
	InfoIgnoreProperty string                                // Info时忽略的字段,多个字段用逗号隔开
	UniqueKey          g.MapStrStr                           // 唯一键 key:字段名 value:错误信息
	NotNullKey         g.MapStrStr                           // 非空键 key:字段名 value:错误信息
}

func NewService

func NewService(model IModel) *Service

NewService 新建一个service

func (*Service) GetModel added in v0.0.18

func (s *Service) GetModel() IModel

GetModel 获取model

func (*Service) ModifyAfter added in v0.0.17

func (s *Service) ModifyAfter(ctx context.Context, method string, param g.MapStrAny) (err error)

ModifyAfter 新增|删除|修改后的操作

func (*Service) ModifyBefore added in v0.3.2

func (s *Service) ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error)

ModifyBefore 新增|删除|修改前的操作

func (*Service) ServiceAdd

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

ServiceAdd 新增

func (*Service) ServiceDelete

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

ServiceDelete 删除

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)

ServiceUpdate 修改

type UpdateReq

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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