micro

package
v1.0.82 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(logger *log.Logger) gin.HandlerFunc

func NewStore

func NewStore(name, dsn, prefix string, keyPairs ...[]byte) (store ginsession.Store, err error)

func NewStoreWithIMDB

func NewStoreWithIMDB(db imdb.Conn, prefix string, keyPairs ...[]byte) ginsession.Store

func OpenDB

func OpenDB(name, dsn string, config interface{}) (*gorm.DB, error)

func Recover

func Recover(logger *log.Logger) gin.HandlerFunc

func RegisterErrorCode

func RegisterErrorCode(codes map[int]int)

RegisterErrorCode 错误码与http状态码映射

func Trace

func Trace(callee string) gin.HandlerFunc

Types

type Controller

type Controller struct{}

func (Controller) Bind

func (c Controller) Bind(ctx *gin.Context, v interface{}) (err error)

func (Controller) ParamInt

func (c Controller) ParamInt(ctx *gin.Context, key string) (i int64, err error)

func (Controller) Response

func (c Controller) Response(ctx *gin.Context, data interface{}, err error)

type CountModel

type CountModel struct {
	CountByYear  int16 `json:"count_by_year" gorm:"index"`  // 按年统计
	CountByMonth int16 `json:"count_by_month" gorm:"index"` // 按月统计
	CountByWeek  int16 `json:"count_by_week" gorm:"index"`  // 按周统计
	CountByDay   int16 `json:"count_by_day" gorm:"index"`   // 按天统计
	CountByHour  int16 `json:"count_by_hour" gorm:"index"`  // 按时统计
}

type Creator added in v1.0.75

type Creator[Model any, Pointer ModelPointer[Model]] struct {
	Dao   Dao
	Errno int
	Equal Equal
	Model Model
}

type Dao

type Dao struct {
	// contains filtered or unexported fields
}

func NewDao

func NewDao(db func(ctx context.Context) *gorm.DB, model schema.Tabler) Dao

func (Dao) Count

func (d Dao) Count(ctx context.Context, equal Equal) (count int64, err error)

func (Dao) Create

func (d Dao) Create(ctx context.Context, equal Equal, value interface{}) (err error)

func (Dao) DB

func (d Dao) DB(ctx context.Context) *gorm.DB

func (Dao) Delete

func (d Dao) Delete(ctx context.Context, equal Equal, update Update) (err error)

func (Dao) Equal

func (d Dao) Equal(ctx context.Context, equal Equal) *gorm.DB

func (Dao) Find

func (d Dao) Find(ctx context.Context, equal Equal, out interface{}) (err error)

func (Dao) First

func (d Dao) First(ctx context.Context, equal Equal, out interface{}) (err error)

func (Dao) List

func (d Dao) List(ctx context.Context, query Query, equal Equal, out interface{}) (total int64, err error)

func (Dao) QueryDeleted

func (d Dao) QueryDeleted(ok bool) Dao

func (Dao) Update

func (d Dao) Update(ctx context.Context, equal Equal, update Update) (err error)

type Deleter added in v1.0.75

type Deleter struct {
	Dao   Dao
	Errno int
	Equal Equal
}

type Equal

type Equal = map[string]any

type Getter added in v1.0.78

type Getter struct {
	Dao   Dao
	Errno int
	Equal Equal
}

type Lister added in v1.0.78

type Lister struct {
	Dao   Dao
	Errno int
	Query Query
}

type Model

type Model struct {
	ModelBase
	ModelExtra
}

type ModelBase added in v1.0.74

type ModelBase struct {
	ID uint `json:"id" gorm:"primary_key"`
}

type ModelExtra added in v1.0.74

type ModelExtra struct {
	CreatedAt int64  `json:"created_at" gorm:"index"`
	UpdatedAt int64  `json:"updated_at" gorm:"index"`
	DeletedAt int64  `json:"deleted_at" gorm:"index"`
	CreatedID string `json:"created_id" gorm:"index"`
	UpdatedID string `json:"updated_id" gorm:"index"`
	DeletedID string `json:"deleted_id" gorm:"index"`
	CreatedBy string `json:"created_by" gorm:"index"`
	UpdatedBy string `json:"updated_by" gorm:"index"`
	DeletedBy string `json:"deleted_by" gorm:"index"`
}

func (*ModelExtra) SetModelExtra added in v1.0.75

func (m *ModelExtra) SetModelExtra(extra ModelExtra)

type ModelPointer added in v1.0.79

type ModelPointer[T any] interface {
	*T
	SetModelExtra(extra ModelExtra)
}

type Query

type Query struct {
	Page   int      `form:"page" json:"page,omitempty"`     // 当前页
	Size   int      `form:"size" json:"size,omitempty"`     // 页大小
	Sort   string   `form:"sort" json:"sort,omitempty"`     // 排序
	Cond   string   `form:"cond" json:"cond,omitempty"`     // 条件符号:and、or,用于自定义字段查询
	Omit   []string `form:"omit" json:"omit,omitempty"`     // 忽略字段
	Select []string `form:"select" json:"select,omitempty"` // 选择字段
	Where  string   `form:"where" json:"where,omitempty"`   // 自定义条件SQL
	// contains filtered or unexported fields
}

func (*Query) ByCustom

func (q *Query) ByCustom(db *gorm.DB) *gorm.DB

func (*Query) ByLimit

func (q *Query) ByLimit(db *gorm.DB) *gorm.DB

func (*Query) ByQuery

func (q *Query) ByQuery(db *gorm.DB) *gorm.DB

func (*Query) BySelect

func (q *Query) BySelect(db *gorm.DB) *gorm.DB

func (*Query) BySort

func (q *Query) BySort(db *gorm.DB) *gorm.DB

func (*Query) ByWhere

func (q *Query) ByWhere(db *gorm.DB) *gorm.DB

func (*Query) Valid

func (q *Query) Valid(ctx *gin.Context) (err error)

type Response

type Response struct {
	Errno   int         `json:"errno"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

func NewResponse

func NewResponse(data interface{}, err error) (resp Response)

NewResponse 创建响应结构

type Result

type Result[Model any, Pointer ModelPointer[Model]] struct {
	Query
	Count int     `json:"count"`
	Total int64   `json:"total"`
	Data  []Model `json:"data"`
}

type Service added in v1.0.75

type Service[User Userinfo, Model any, Pointer ModelPointer[Model]] struct {
	Session Session[User]
}

func NewService added in v1.0.76

func NewService[User Userinfo, Model any, Pointer ModelPointer[Model]](s Session[User]) Service[User, Model, Pointer]

func (*Service[User, Model, Pointer]) Create added in v1.0.75

func (s *Service[User, Model, Pointer]) Create(ctx context.Context, create Creator[Model, Pointer]) (m *Model, err error)

func (*Service[User, Model, Pointer]) Delete added in v1.0.75

func (s *Service[User, Model, Pointer]) Delete(ctx context.Context, delete Deleter) (m *Model, err error)

func (*Service[User, Model, Pointer]) Get added in v1.0.78

func (s *Service[User, Model, Pointer]) Get(ctx context.Context, get Getter) (m *Model, err error)

func (*Service[User, Model, Pointer]) List added in v1.0.78

func (s *Service[User, Model, Pointer]) List(ctx context.Context, list Lister) (result *Result[Model, Pointer], err error)

func (*Service[User, Model, Pointer]) Update added in v1.0.75

func (s *Service[User, Model, Pointer]) Update(ctx context.Context, update Updater) (m *Model, err error)

type Session added in v1.0.79

type Session[User Userinfo] interface {
	GetUser(ctx context.Context) (user User, err error)
}

type Update

type Update = map[string]any

type Updater added in v1.0.75

type Updater struct {
	Dao    Dao
	Errno  int
	Equal  Equal
	Update Update
}

type Userinfo added in v1.0.79

type Userinfo interface {
	CreateModel(now time.Time) ModelExtra
	UpdateModel(model Model, now time.Time) Model
	DeleteModel(now time.Time) Update
	Update(update Update, now time.Time) Update
}

type Validator

type Validator interface {
	Valid(ctx *gin.Context) (err error)
}

Jump to

Keyboard shortcuts

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