Documentation ¶
Overview ¶
controllers/base_controller.go
models/IModel.go
app/ISchema.go
service/base_service.go
Index ¶
- func DTOListToModelList[TDTO any, T any](dtos []TDTO) ([]T, error)
- func DTOToModel(dto interface{}, model interface{})
- func MapToStructWithColumn(m map[string]interface{}, s interface{}) error
- func ModelListToVOList[T IModel, TVO IVO](modelList []T) (*[]TVO, error)
- func ModelToVO[T1 any, T2 any](model T1, voPointer interface{}) error
- func StructToMapWithColumn(s interface{}) (map[string]interface{}, error)
- type BaseController
- func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) BulkCreate(c *gin.Context)
- func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) BulkDelete(c *gin.Context)
- func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) Create(c *gin.Context)
- func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) Delete(c *gin.Context)
- func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) GetById(c *gin.Context)
- func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) GetTreeById(c *gin.Context)
- func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) PageByDTO(c *gin.Context)
- func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) TreePage(c *gin.Context)
- func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) Update(c *gin.Context)
- func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) UpdateByMap(c *gin.Context)
- type BaseDTO
- type BaseService
- func (bs *BaseService[T]) BulkCreate(models []T) (int, *[]T, error)
- func (bs *BaseService[T]) BulkDelete(ids []string) (int, error)
- func (bs *BaseService[T]) Create(model T) (*T, error)
- func (bs *BaseService[T]) Delete(id string) error
- func (bs *BaseService[T]) GetById(id string) (*T, error)
- func (bs *BaseService[T]) GetTreeById(id string) (*[]T, error)
- func (bs *BaseService[T]) PageByDTO(queryDto interface{}, queryPage *QueryPage) (*[]T, int, error)
- func (bs *BaseService[T]) TreePageByDTO(queryDto interface{}, queryPage *QueryPage) (*[]T, int, error)
- func (bs *BaseService[T]) Update(id string, model T) (*T, error)
- func (bs *BaseService[T]) UpdateByMap(id string, dtoMap map[string]interface{}) error
- type BaseVO
- type GenericModel
- type IBaseController
- type IBaseService
- type ICreateDTO
- type IModel
- type IQueryDTO
- type IVO
- type MixinModel
- type OperatorModel
- type PaginationResult
- type QueryPage
- type SnowflakeIDModel
- type SoftDeleteModel
- type TimeStampsModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DTOListToModelList ¶
func DTOToModel ¶
func DTOToModel(dto interface{}, model interface{})
func MapToStructWithColumn ¶
MapToStructWithColumnTag 将包含gorm column标签作为键的map转换为结构体
func ModelListToVOList ¶
转换函数
func StructToMapWithColumn ¶
StructToMapWithColumnTag 将结构体转换为map,使用gorm的column标签作为key
Types ¶
type BaseController ¶
type BaseController[T IModel, CreateDTO ICreateDTO, QueryDTO IQueryDTO, TVO IVO] struct { Service IBaseService[T] }
BaseController 是一个泛型基类,提供CRUD方法的默认实现。
func NewBaseController ¶
func NewBaseController[T IModel, CreateDTO ICreateDTO, QueryDTO IQueryDTO, TVO IVO](s IBaseService[T]) *BaseController[T, CreateDTO, QueryDTO, TVO]
NewBaseController 创建一个新的 BaseController 实例。
func (*BaseController[T, CreateDTO, QueryDTO, TVO]) BulkCreate ¶
func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) BulkCreate(c *gin.Context)
批量创建
func (*BaseController[T, CreateDTO, QueryDTO, TVO]) BulkDelete ¶
func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) BulkDelete(c *gin.Context)
Deletes 删除资源
func (*BaseController[T, CreateDTO, QueryDTO, TVO]) Create ¶
func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) Create(c *gin.Context)
func (*BaseController[T, CreateDTO, QueryDTO, TVO]) Delete ¶
func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) Delete(c *gin.Context)
Delete 删除资源
func (*BaseController[T, CreateDTO, QueryDTO, TVO]) GetById ¶
func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) GetById(c *gin.Context)
Get 读取资源
func (*BaseController[T, CreateDTO, QueryDTO, TVO]) GetTreeById ¶
func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) GetTreeById(c *gin.Context)
func (*BaseController[T, CreateDTO, QueryDTO, TVO]) PageByDTO ¶
func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) PageByDTO(c *gin.Context)
func (*BaseController[T, CreateDTO, QueryDTO, TVO]) TreePage ¶
func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) TreePage(c *gin.Context)
func (*BaseController[T, CreateDTO, QueryDTO, TVO]) Update ¶
func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) Update(c *gin.Context)
Update 更新资源,接收 DTO 类型的参数,并将其转换为模型后提交到服务操作
func (*BaseController[T, CreateDTO, QueryDTO, TVO]) UpdateByMap ¶
func (bc *BaseController[T, CreateDTO, QueryDTO, TVO]) UpdateByMap(c *gin.Context)
type BaseService ¶
BaseService 定义了一个通用的基础服务,提供了一些通用的字段和方法。
func NewBaseService ¶
func NewBaseService[T IModel](db *gorm.DB, model T) *BaseService[T]
NewBaseService 创建一个新的 BaseService 实例。
func (*BaseService[T]) BulkCreate ¶
func (bs *BaseService[T]) BulkCreate(models []T) (int, *[]T, error)
BulkCreate 实现批量创建
func (*BaseService[T]) BulkDelete ¶
func (bs *BaseService[T]) BulkDelete(ids []string) (int, error)
Create 实现基础服务接口中的创建方法
func (*BaseService[T]) Create ¶
func (bs *BaseService[T]) Create(model T) (*T, error)
Create 实现基础服务接口中的创建方法
func (*BaseService[T]) Delete ¶
func (bs *BaseService[T]) Delete(id string) error
Delete 实现基础服务接口中的删除方法
func (*BaseService[T]) GetById ¶
func (bs *BaseService[T]) GetById(id string) (*T, error)
Read 实现基础服务接口中的读取方法
func (*BaseService[T]) GetTreeById ¶
func (bs *BaseService[T]) GetTreeById(id string) (*[]T, error)
func (*BaseService[T]) PageByDTO ¶
func (bs *BaseService[T]) PageByDTO(queryDto interface{}, queryPage *QueryPage) (*[]T, int, error)
return &models, int(count), nil }
func (*BaseService[T]) TreePageByDTO ¶
func (bs *BaseService[T]) TreePageByDTO(queryDto interface{}, queryPage *QueryPage) (*[]T, int, error)
func (*BaseService[T]) Update ¶
func (bs *BaseService[T]) Update(id string, model T) (*T, error)
Update 实现基础服务接口中的更新方法
func (*BaseService[T]) UpdateByMap ¶
func (bs *BaseService[T]) UpdateByMap(id string, dtoMap map[string]interface{}) error
Update 实现基础服务接口中的更新方法
type BaseVO ¶
type BaseVO struct{}
func (BaseVO) GetDetailVO ¶
func (BV BaseVO) GetDetailVO() interface{}
type GenericModel ¶
type IBaseController ¶
type IBaseService ¶
type IBaseService[T IModel] interface { Create(model T) (*T, error) BulkCreate(models []T) (int, *[]T, error) // CreateOrUpdateByKeys(keys []string, model T, many bool) (int64, error) // CreateOrUpdateByDTO(model T) (*T, error) GetById(id string) (*T, error) Update(id string, model T) (*T, error) Delete(id string) error BulkDelete(ids []string) (int, error) PageByDTO(queryDto interface{}, queryPage *QueryPage) (*[]T, int, error) TreePageByDTO(queryDto interface{}, queryPage *QueryPage) (*[]T, int, error) GetTreeById(id string) (*[]T, error) UpdateByMap(id string, dtoMap map[string]interface{}) error }
IBaseService 定义了基础服务接口,任何具体服务都应该实现这些方法。
type ICreateDTO ¶
type ICreateDTO interface { }
type MixinModel ¶
type MixinModel struct { SnowflakeIDModel OperatorModel TimeStampsModel GenericModel }
type OperatorModel ¶
type PaginationResult ¶
type QueryPage ¶
type SnowflakeIDModel ¶
type SnowflakeIDModel struct {
Id int64 `gorm:"primaryKey;autoIncrement:false" json:"Id,string"`
}
SnowflakeIDModel 是基于雪花算法生成唯一标识的基础模型
func (*SnowflakeIDModel) BeforeCreate ¶
func (m *SnowflakeIDModel) BeforeCreate(tx *gorm.DB) error
BeforeCreate 在创建记录前为模型生成雪花算法ID