athena

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxHttpStatusCode = "athena_httpStatusCode"
	CtxCode           = "athena_code"
	CtxMessage        = "athena_message"
)
View Source
const DateFormat = "2006-01-02"
View Source
const DateTimeFormat = "2006-01-02 15:04:05"

Variables

View Source
var ResponderList []Responder
View Source
var ResponsePool *sync.Pool

Functions

func Convert

func Convert(handler interface{}) gin.HandlerFunc

func Error

func Error(err error, msg ...string)

func Unwrap

func Unwrap(result any, err error) any

func UnwrapOrEmpty

func UnwrapOrEmpty(result string, err error) string

Types

type AnyResponder

type AnyResponder func(ctx *gin.Context) any

func (AnyResponder) RespondTo

func (this AnyResponder) RespondTo() gin.HandlerFunc

type Athena

type Athena struct {
	*gin.Engine
	// contains filtered or unexported fields
}

func Ignite

func Ignite() *Athena

func (*Athena) Attach

func (this *Athena) Attach(f interfaces.IFairing) *Athena

Attach 加入全局中间件

func (*Athena) Beans

func (this *Athena) Beans(beans ...any) *Athena

Beans 依赖注入对象

func (*Athena) Configuration

func (this *Athena) Configuration(cfgs ...any) *Athena

Configuration 定义配置类,会被自动扫描注册到bean对象

func (*Athena) CronTask

func (this *Athena) CronTask(expr string, f func()) *Athena

CronTask 创建定时任务

func (*Athena) Handle

func (this *Athena) Handle(httpMethod, relativePath string, handler interface{}) *Athena

func (*Athena) Launch

func (this *Athena) Launch()

Launch 最终启动函数

func (*Athena) MappingConfig

func (this *Athena) MappingConfig(entity config.IConfig, decoderConfigOpts ...viper.DecoderConfigOption) *Athena

MappingConfig 映射配置文件到实体对象中

func (*Athena) Mount

func (this *Athena) Mount(group string, fs []interfaces.IFairing, classes ...IClass) *Athena

Mount 挂载

func (*Athena) RegisterPlugin

func (this *Athena) RegisterPlugin(plugins ...interfaces.IPlugin) *Athena

RegisterPlugin 注册插件

type Collection

type Collection struct {
	Items any   `json:"items"`
	Page  *Page `json:"page"`
}

Collection 分页集合

func NewCollection

func NewCollection(items any, page *Page) *Collection

type CollectionResponder

type CollectionResponder func(ctx *gin.Context) Collection

func (CollectionResponder) RespondTo

func (this CollectionResponder) RespondTo() gin.HandlerFunc

type Conditions

type Conditions struct {
	Query any
	Args  []any
}

Conditions 自定义 where 条件

func NewConditions

func NewConditions(query any, args ...any) *Conditions

func NewConditionsWithQuery

func NewConditionsWithQuery(query any) *Conditions

NewConditionsWithQuery 根据注解生成 where 条件

type DateTime

type DateTime time.Time

DateTime 自定义时间格式

func (*DateTime) IsZero

func (t *DateTime) IsZero() bool

func (*DateTime) MarshalJSON

func (t *DateTime) MarshalJSON() ([]byte, error)

func (*DateTime) UnmarshalJSON

func (t *DateTime) UnmarshalJSON(data []byte) (err error)

type DbQuery added in v1.0.8

type DbQuery struct {
	Db       *gorm.DB    `json:"-"`
	Debug    bool        `json:"-"`
	Order    string      `json:"-"`
	Fields   []string    `json:"-"`
	Preloads []*Preload  `json:"-"`
	Joins    []*Join     `json:"-"`
	Where    *Conditions `json:"-"`
}

DbQuery 查询对象

func NewDbQuery added in v1.0.8

func NewDbQuery() *DbQuery

func (*DbQuery) AddFields added in v1.0.8

func (this *DbQuery) AddFields(fields ...string) *DbQuery

AddFields 设置查询字段

func (*DbQuery) AddJoins added in v1.0.8

func (this *DbQuery) AddJoins(joins ...*Join) *DbQuery

AddJoins 设置关联

func (*DbQuery) AddPreloads added in v1.0.8

func (this *DbQuery) AddPreloads(preloads ...*Preload) *DbQuery

AddPreloads 设置预加载

func (*DbQuery) SetBuildOpts added in v1.0.8

func (this *DbQuery) SetBuildOpts(build *gorm.DB) *gorm.DB

SetCountBuildOpts 设置查询选项

func (*DbQuery) SetCountBuildOpts added in v1.0.8

func (this *DbQuery) SetCountBuildOpts(countBuild *gorm.DB) *gorm.DB

SetCountBuildOpts 设置统计数量的查询选项

func (*DbQuery) SetDb added in v1.0.8

func (this *DbQuery) SetDb(db *gorm.DB) *DbQuery

SetDb 设置db对象

func (*DbQuery) SetDebug added in v1.0.8

func (this *DbQuery) SetDebug() *DbQuery

SetDb 设置Debug

func (*DbQuery) SetOrder added in v1.0.8

func (this *DbQuery) SetOrder(order string) *DbQuery

SetOrder 设置排序

func (*DbQuery) SetWhere added in v1.0.8

func (this *DbQuery) SetWhere(where *Conditions) *DbQuery

SetWhere 设置查询条件

type IClass

type IClass interface {
	Build(athena *Athena)
}

type Join added in v1.0.7

type Join struct {
	Query string
	Args  []any
}

Join 关联

func NewJoin added in v1.0.7

func NewJoin(query string, args ...any) *Join

type Json

type Json map[string]any

type JsonResponder

type JsonResponder func(*gin.Context) Json

func (JsonResponder) RespondTo

func (this JsonResponder) RespondTo() gin.HandlerFunc

type Model

type Model interface {
	TableName() string
}

type Models

type Models string

func MakeModels

func MakeModels(v interface{}) Models

type Page

type Page struct {
	*DbQuery
	CurrentPage int   `json:"current_page"`     // 当前页
	PerPage     int   `json:"per_page"`         // 每页条数
	TotalSize   int64 `json:"total_size"`       // 总条数
	TotalPage   int   `json:"total_page"`       // 总页数
	Extend      any   `json:"extend,omitempty"` // 扩展字段
}

Page 快速分页对象

func NewPage

func NewPage(currentPage int, perPage int) *Page

func NewPageWithCtx

func NewPageWithCtx(ctx *gin.Context) *Page

NewPageWithCtx 通过 query 参数创建

func (*Page) GetOffset

func (this *Page) GetOffset() int

GetOffset 获取 Offset

func (*Page) IsValid

func (this *Page) IsValid() bool

IsValid 是否有效

func (*Page) SelectList

func (this *Page) SelectList(items any) *gorm.DB

SelectList 列表查询

func (*Page) SetTotal

func (this *Page) SetTotal(totalSize int64)

SetTotal 设置总条数和总页数

func (*Page) SlicePage

func (this *Page) SlicePage(list []any) (start int, end int64)

SlicePage 切片分页

type Preload

type Preload struct {
	Query string
	Args  []any
}

Preload 自定义预加载

func NewPreload

func NewPreload(query string, args ...any) *Preload

type Responder

type Responder interface {
	RespondTo() gin.HandlerFunc
}

type Response

type Response struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
}

type StringResponder

type StringResponder func(*gin.Context) string

func (StringResponder) RespondTo

func (this StringResponder) RespondTo() gin.HandlerFunc

type Void

type Void struct{}

type VoidResponder

type VoidResponder func(ctx *gin.Context) Void

func (VoidResponder) RespondTo

func (this VoidResponder) RespondTo() gin.HandlerFunc

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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