g

package
v0.0.71 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: BSD-3-Clause Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecordRepeat = errors.New("数据已经存在")
	ErrDateBusy     = errors.New("数据在使用")
)
View Source
var (
	// Conf All 配置
	Conf *conf.Config

	// CacheLocal
	// 1.一级缓存 变动小、容量少。容量固定,有淘汰策略。
	// 2.不适合分布式数据共享。
	CacheLocal *cache.Cache

	// CacheDB 二级缓存 容量大,有网络IO延迟
	CacheDB redis.Cmdable

	// DB gorm 关系型数据库 -- 持久化
	DB *gorm.DB
)

Functions

This section is empty.

Types

type Error

type Error struct {
	Inner      error
	Text       string // 业务错误信息,通常是中文提示,返回给客户端
	StackTrace string
	Misc       map[string]any // miscellaneous(各种各样) information
}

Error 自定义错误

func NewError

func NewError(message string) *Error

func NewErrorf

func NewErrorf(format string, a ...any) *Error

func WrapError

func WrapError(err error, message string) *Error

WrapError new Error

func (*Error) Error

func (err *Error) Error() string

func (*Error) Is

func (err *Error) Is(target error) bool

Is inner error 断言

func (*Error) Unwrap

func (err *Error) Unwrap() error

Unwrap 返回 inner error

type FindByIDService added in v0.0.6

type FindByIDService[T any] struct{}

func (*FindByIDService[T]) FindByID added in v0.0.6

func (*FindByIDService[T]) FindByID(tx *gorm.DB, id string) (T, *Error)

type IBase

type IBase[T any, Q any] interface {
	PageList(Q) (*r.PageResp[T], *Error)
	Create(T) *Error
	Update(T) *Error
	Delete(int) *Error
}

type IBaseApi

type IBaseApi interface {
	PageList(ctx *gin.Context)
	Create(ctx *gin.Context)
	Update(ctx *gin.Context)
	Delete(ctx *gin.Context)
}

type UniqueService added in v0.0.6

type UniqueService[T any] struct{}

UniqueService 校验传入值是否已经在数据库中存在 T 表示要查询表的Model k为 'id' 作为排除,比如更新时

type UserService struct{
	g.Unique[model.User]
}

func (*UniqueService[T]) Verify added in v0.0.6

func (*UniqueService[T]) Verify(tx *gorm.DB, q map[string]any) *Error

Jump to

Keyboard shortcuts

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