corebase

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BasePageNum   = 1
	BasePageSize  = 10
	BaseListLimit = 1000
)

Functions

func RegisterController

func RegisterController(group *gin.RouterGroup, c IController, apis []string, extendRouter map[string]*RouterItem, 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, fileds map[string]string) *gorm.DB

func ValidStuct

func ValidStuct(stu interface{}) error

*

  • 验证结构体内的字段数据是否符合要求
  • @Param stu 需要验证的结构体
  • @Any errMsg 在结构体的tag中定义的字段
  • @Any 包含五种验证:phone、chinese、letter、stand、car

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返回的时间类型格式不规范,所以这里自己重新定义一下

func NewBaseModel added in v1.0.5

func NewBaseModel() *BaseModel

初始化BaseModel。(没什么用,仅占位)

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"` // 大于
	FiledsParam []*QueryFild `json:"filedsParams"`
	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 NewController added in v1.0.5

func NewController(pre string, mod string, source ISource) *Controller

初始化Controller实例

func (*Controller) Del

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

删除

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) // 分页查询和全部查询
}

type IModel

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

type ISource

type ISource interface {
	SourceSave(map[string]any, bool) (uint, error)
	SourceDel([]uint) (int64, error)
	SourceInfo(id uint) (interface{}, error)
	SourcePage(*BaseSearch) (interface{}, error)
	SourceList(*BaseSearch) (interface{}, error)
	GetModelName() string
	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 RouterItem added in v1.0.2

type RouterItem struct {
	From string
	Call func(ctx *gin.Context)
}

type Source

type Source struct {
	ModelName  string
	Model      IModel
	Database   before.IDatabaseConnect
	FiledTypes map[string]string // 字段类型
	FieldOmits []string
}

*

  • ModelName
  • Model
  • Database

func NewSource added in v1.0.5

func NewSource() *Source

实例化示例

func (*Source) GetModel

func (s *Source) GetModel() IModel

func (*Source) GetModelName added in v1.0.14

func (s *Source) GetModelName() string

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 map[string]any, isAdd bool) (uint, error)

*

  • 新增和修改

Jump to

Keyboard shortcuts

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