corebase

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BasePageNum   = 1
	BasePageSize  = 10
	BaseListLimit = 1000
)
View Source
var ModelMigrateErr = []string{}

用于搜集迁移失败的数据

Functions

func MigrateJoinTable

func MigrateJoinTable(mainModel IModel, col string, followModel IModel)

数据库中间表迁移

func MigrateTable

func MigrateTable(model IModel)

数据库表迁移

func RegisterController

func RegisterController(c IController, apis []string, extendRouter func(router *gin.RouterGroup), middle ...func(ctx *gin.Context)) error

func SourceFieldsFiltter

func SourceFieldsFiltter(db *gorm.DB, filter []string) *gorm.DB

func SourceSearchWhere

func SourceSearchWhere(db *gorm.DB, search *BaseSearch) *gorm.DB

func ValidStuct

func ValidStuct(stu interface{}) error

*

  • 验证结构体内的字段数据是否符合要求
  • @Param stu 需要验证的结构体
  • @Any errInfo 在结构体的tag中定义的字段

Types

type BaseModel

type BaseModel struct {
	ID        uint                  `gorm:"primarykey" json:"id"`
	CreatedAt customType.CustomTime `gorm:"comment:创建时间" json:"createdAt"`
	UpdatedAt customType.CustomTime `gorm:"comment:更新时间" json:"updatedAt"`
	DeletedAt gorm.DeletedAt        `gorm:"index" json:"-"`
}

因为gorm自带的model返回的时间类型格式不规范,所以这里自己重新定义一下

type BasePage

type BasePage struct {
	PageSize  int   `json:"pageSize"`
	PageNum   int   `json:"pageNum"`
	PageTotal int64 `json:"pageTotal"`
}

type BaseSearch

type BaseSearch struct {
	Equal   []*QueryFild `json:"equal"`   // 精确查询
	Like    []*QueryFild `json:"like"`    // 模糊查询
	Less    []*QueryFild `json:"less"`    // 小于
	Greater []*QueryFild `json:"greater"` // 大于
	Page    int          `json:"page"`    // 当前页
	Size    int          `json:"size"`    // 一页多少条数据
	Order   string       `json:"order"`   // 排序字段
	Sort    string       `json:"sort"`    // 排序方式
}

type Controller

type Controller struct {
	Prefix string
	Module string
	Source ISource
}

func (*Controller) Del

func (c *Controller) Del(ctx *gin.Context)

删除

func (*Controller) GetPrefix

func (c *Controller) GetPrefix() string

获取分组

func (*Controller) Info

func (c *Controller) Info(ctx *gin.Context)

详情

func (*Controller) Save

func (c *Controller) Save(ctx *gin.Context, isAdd bool)

增加和修改

func (*Controller) Table

func (c *Controller) Table(ctx *gin.Context, isPage bool)

列表

type IController

type IController interface {
	Save(*gin.Context, bool) // 新增和修改
	Del(*gin.Context)
	Info(*gin.Context)
	Table(*gin.Context, bool) // 分页查询和全部查询
	GetPrefix() string
}

type IModel

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

type ISource

type ISource interface {
	SourceSave(interface{}, bool) (uint, error)
	SourceDel([]uint) (int64, error)
	SourceInfo(id uint) (interface{}, error)
	SourcePage(*BaseSearch) (interface{}, error)
	SourceList(*BaseSearch) (interface{}, error)
	GetModel() IModel
}

type PageResult

type PageResult struct {
	Page *BasePage   `json:"page"`
	List interface{} `json:"list"`
}

type QueryFild

type QueryFild struct {
	Field string      `json:"field"`
	Value interface{} `json:"value"` // 可以是数字、数字切片、字符串
}

type Source

type Source struct {
	Model           IModel
	TableOmitFields []string
}

func (*Source) GetModel

func (s *Source) GetModel() IModel

func (*Source) SourceDel

func (s *Source) SourceDel(ids []uint) (int64, error)

*

  • 删除

func (*Source) SourceInfo

func (s *Source) SourceInfo(id uint) (interface{}, error)

*

  • 详情(各自实例的详情需自行实现)

func (*Source) SourceList

func (s *Source) SourceList(search *BaseSearch) (interface{}, error)

*

  • 列表

func (*Source) SourcePage

func (s *Source) SourcePage(search *BaseSearch) (interface{}, error)

*

  • 分页

func (*Source) SourceSave

func (s *Source) SourceSave(data interface{}, isAdd bool) (uint, error)

*

  • 新增和修改

Jump to

Keyboard shortcuts

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