ginger

package module
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: MIT Imports: 14 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CRON

func CRON(engine IEngine, spec string, job func())

func DELETE

func DELETE[T any](engine IEngine, route string, handler ApiHandler[T], middleware ...gin.HandlerFunc)

func DELETECached

func DELETECached[T any](engine IEngine, route string, handler ApiHandler[T], duration time.Duration, middleware ...gin.HandlerFunc)

func GET

func GET[T any](engine IEngine, route string, handler ApiHandler[T], middleware ...gin.HandlerFunc)

func GETCached

func GETCached[T any](engine IEngine, route string, handler ApiHandler[T], duration time.Duration, middleware ...gin.HandlerFunc)

func GetError

func GetError(code string, locale ...string) string

func POST

func POST[T any](engine IEngine, route string, handler ApiHandler[T], middleware ...gin.HandlerFunc)

func POSTCached

func POSTCached[T any](engine IEngine, route string, handler ApiHandler[T], duration time.Duration, middleware ...gin.HandlerFunc)

func PUT

func PUT[T any](engine IEngine, route string, handler ApiHandler[T], middleware ...gin.HandlerFunc)

func PUTCached

func PUTCached[T any](engine IEngine, route string, handler ApiHandler[T], duration time.Duration, middleware ...gin.HandlerFunc)

func RegisterError

func RegisterError(code, message string, locale ...string)

func WS

func WS[T any](engine IEngine, route string, handler WsHandler[T], middleware ...gin.HandlerFunc)

Types

type ApiHandler

type ApiHandler[T any] func() ApiService[T]

func (ApiHandler[T]) GinHandler

func (h ApiHandler[T]) GinHandler(engine IEngine) gin.HandlerFunc

type ApiService

type ApiService[T any] func(ctx IContext[T])

type Context

type Context[T any] struct {
	Engine    IEngine
	GinCtx    *gin.Context
	Page      *sql.Pagination
	Sort      *sql.Sort
	Request   *T
	Response  *Response
	StartTime time.Time
	IsFile    bool
	IsResp    bool
}

func (*Context[T]) BearerToken

func (ctx *Context[T]) BearerToken() string

func (*Context[T]) ClientIP

func (ctx *Context[T]) ClientIP() string

func (*Context[T]) Err

func (ctx *Context[T]) Err(code string, locale ...string)

func (*Context[T]) GetEngine

func (ctx *Context[T]) GetEngine() IEngine

func (*Context[T]) GetGinCtx

func (ctx *Context[T]) GetGinCtx() *gin.Context

func (*Context[T]) GetIsFile

func (ctx *Context[T]) GetIsFile() bool

func (*Context[T]) GetIsResponded

func (ctx *Context[T]) GetIsResponded() bool

func (*Context[T]) GetPage

func (ctx *Context[T]) GetPage() *sql.Pagination

func (*Context[T]) GetRequest

func (ctx *Context[T]) GetRequest() *T

func (*Context[T]) GetResponse

func (ctx *Context[T]) GetResponse() *Response

func (*Context[T]) GetSort

func (ctx *Context[T]) GetSort() *sql.Sort

func (*Context[T]) GetStartTime

func (ctx *Context[T]) GetStartTime() time.Time

func (*Context[T]) OK

func (ctx *Context[T]) OK(data any, page ...*sql.Pagination)

func (*Context[T]) OKDownload added in v1.1.9

func (ctx *Context[T]) OKDownload(bytes []byte, filename ...string)

func (*Context[T]) OKFile added in v1.1.9

func (ctx *Context[T]) OKFile(bytes []byte, filename ...string)

func (*Context[T]) SetEngine

func (ctx *Context[T]) SetEngine(engine IEngine)

func (*Context[T]) SetGinCtx

func (ctx *Context[T]) SetGinCtx(ginCtx *gin.Context)

func (*Context[T]) SetIsFile

func (ctx *Context[T]) SetIsFile(isFile bool)

func (*Context[T]) SetIsResponded

func (ctx *Context[T]) SetIsResponded(isResp bool)

func (*Context[T]) SetPage

func (ctx *Context[T]) SetPage(page *sql.Pagination)

func (*Context[T]) SetRequest

func (ctx *Context[T]) SetRequest(request *T)

func (*Context[T]) SetResponse

func (ctx *Context[T]) SetResponse(response *Response)

func (*Context[T]) SetSort

func (ctx *Context[T]) SetSort(sort *sql.Sort)

func (*Context[T]) SetStartTime

func (ctx *Context[T]) SetStartTime(startTime time.Time)

func (*Context[T]) UserAgent

func (ctx *Context[T]) UserAgent() string

type Engine

type Engine struct {
	Gin  *gin.Engine
	Cron *cron.Cron
}

func (*Engine) GetCron

func (e *Engine) GetCron() *cron.Cron

func (*Engine) GetGin

func (e *Engine) GetGin() *gin.Engine

func (*Engine) Run added in v1.1.2

func (e *Engine) Run(addr ...string)

func (*Engine) SetCron

func (e *Engine) SetCron(c *cron.Cron)

func (*Engine) SetGin

func (e *Engine) SetGin(g *gin.Engine)

type Error

type Error struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

func (*Error) GetCode

func (e *Error) GetCode() string

func (*Error) GetMessage

func (e *Error) GetMessage() string

func (*Error) SetCode

func (e *Error) SetCode(code string)

func (*Error) SetMessage

func (e *Error) SetMessage(msg string)

type IContext

type IContext[T any] interface {
	GetEngine() IEngine
	SetEngine(engine IEngine)
	GetGinCtx() *gin.Context
	SetGinCtx(ginCtx *gin.Context)

	GetPage() *sql.Pagination
	SetPage(page *sql.Pagination)
	GetSort() *sql.Sort
	SetSort(sort *sql.Sort)
	GetResponse() *Response
	SetResponse(resp *Response)
	GetRequest() *T
	SetRequest(req *T)

	GetStartTime() time.Time
	SetStartTime(startTime time.Time)
	GetIsFile() bool
	SetIsFile(isFile bool)
	GetIsResponded() bool
	SetIsResponded(isResp bool)

	ClientIP() string
	UserAgent() string
	BearerToken() string

	OK(data any, page ...*sql.Pagination)
	OKFile(bytes []byte, filename ...string)
	OKDownload(bytes []byte, filename ...string)
	Err(code string, locale ...string)
}

func MockContext

func MockContext[T any](params MockContextParams[T]) IContext[T]

func NewContext

func NewContext[T any](
	engine IEngine,
	ginCtx *gin.Context,
) IContext[T]

type IEngine

type IEngine interface {
	GetGin() *gin.Engine
	GetCron() *cron.Cron
	SetGin(g *gin.Engine)
	SetCron(c *cron.Cron)
	Run(addr ...string)
}

func NewEngine

func NewEngine() IEngine

type IError

type IError interface {
	GetCode() string
	GetMessage() string
	SetCode(code string)
	SetMessage(msg string)
}

func NewError

func NewError(code, locale string) IError

type MockContextParams

type MockContextParams[T any] struct {
	Request   *T
	Page      *sql.Pagination
	Sort      *sql.Sort
	Method    string
	Path      string
	ClientIP  string
	UserAgent string
	Headers   map[string]string
}

type Response

type Response struct {
	Success    bool            `json:"success"`
	Duration   int64           `json:"duration"`
	Pagination *sql.Pagination `json:"pagination,omitempty"`
	Error      *Error          `json:"error,omitempty"`
	Data       interface{}     `json:"data,omitempty"`
}

type WsHandler

type WsHandler[T any] func() WsService[T]

func (WsHandler[T]) GinHandler

func (h WsHandler[T]) GinHandler(engine IEngine) gin.HandlerFunc

type WsService

type WsService[T any] func(ctx IContext[T]) *Error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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