ginger

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 12 Imported by: 0

README

Gin Wrapper

Installation

go get -u github.com/Metadiv-Technology-Limited/ginger

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApiServiceToGinHandler

func ApiServiceToGinHandler[T any](engine IEngine, service func(ctx IContext[T])) gin.HandlerFunc

func CRON

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

func DELETE

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

func DELETECached

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

func GET

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

func GETCached

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

func POST

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

func POSTCached

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

func PUT

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

func PUTCached

func PUTCached[T any](engine IEngine, route string, handler Handler[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 Handler[T], middleware ...gin.HandlerFunc)

func WsServiceToGinHandler

func WsServiceToGinHandler[T any](engine IEngine, service func(ctx IContext[T])) gin.HandlerFunc

Types

type Context

type Context[T any] struct {
	Engine   IEngine
	GinCtx   *gin.Context
	Page     models.IPagination
	Sort     models.ISorting
	Request  *T
	Response IResponse
	StartAt  time.Time
	HasResp  bool
	IsFile   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]) Forbidden added in v1.2.0

func (ctx *Context[T]) Forbidden(msg ...string)

func (*Context[T]) GetEngine

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

func (*Context[T]) GetGinCtx

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

func (*Context[T]) GetHasResp

func (c *Context[T]) GetHasResp() bool

func (*Context[T]) GetIsFile

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

func (*Context[T]) GetPage

func (c *Context[T]) GetPage() models.IPagination

func (*Context[T]) GetRequest

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

func (*Context[T]) GetResponse

func (c *Context[T]) GetResponse() IResponse

func (*Context[T]) GetSort

func (c *Context[T]) GetSort() models.ISorting

func (*Context[T]) GetStartAt

func (c *Context[T]) GetStartAt() time.Time

func (*Context[T]) InternalServerError added in v1.2.0

func (ctx *Context[T]) InternalServerError(msg ...string)

func (*Context[T]) OK

func (ctx *Context[T]) OK(data any, page ...models.IPagination)

func (*Context[T]) OKDownload

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

func (*Context[T]) OKFile

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

func (*Context[T]) SetEngine

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

func (*Context[T]) SetGinCtx

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

func (*Context[T]) SetHasResp

func (c *Context[T]) SetHasResp(hasResp bool)

func (*Context[T]) SetIsFile

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

func (*Context[T]) SetPage

func (c *Context[T]) SetPage(page models.IPagination)

func (*Context[T]) SetRequest

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

func (*Context[T]) SetResponse

func (c *Context[T]) SetResponse(response IResponse)

func (*Context[T]) SetSort

func (c *Context[T]) SetSort(sort models.ISorting)

func (*Context[T]) SetStartAt

func (c *Context[T]) SetStartAt(startAt time.Time)

func (*Context[T]) Unauthorized added in v1.2.0

func (ctx *Context[T]) Unauthorized(msg ...string)

func (*Context[T]) UserAgent

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

type Engine

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

func NewEngine added in v1.3.0

func NewEngine() *Engine

func (*Engine) GetCron

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

func (*Engine) GetGin

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

func (*Engine) Run

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

func (*Engine) SetCron

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

func (*Engine) SetGin

func (e *Engine) SetGin(gin *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(message string)

type Handler

type Handler[T any] Service[T]

type IContext

type IContext[T any] interface {
	GetEngine() IEngine
	SetEngine(IEngine)
	GetGinCtx() *gin.Context
	SetGinCtx(*gin.Context)
	GetPage() models.IPagination
	SetPage(models.IPagination)
	GetSort() models.ISorting
	SetSort(models.ISorting)
	GetRequest() *T
	SetRequest(*T)
	GetResponse() IResponse
	SetResponse(IResponse)
	GetStartAt() time.Time
	SetStartAt(time.Time)
	GetHasResp() bool
	SetHasResp(bool)
	GetIsFile() bool
	SetIsFile(bool)
	BearerToken() string
	ClientIP() string
	UserAgent() string
	OK(data any, page ...models.IPagination)
	OKFile(bytes []byte, filename ...string)
	OKDownload(bytes []byte, filename ...string)
	Err(code string, locale ...string)
	InternalServerError(msg ...string)
	Forbidden(msg ...string)
	Unauthorized(msg ...string)
}

func NewContext

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

type IEngine

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

type IError

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

type IResponse

type IResponse interface {
	GetSuccess() bool
	SetSuccess(bool)
	GetDuration() int64
	SetDuration(int64)
	GetPagination() models.IPagination
	SetPagination(models.IPagination)
	GetError() IError
	SetError(IError)
	GetData() any
	SetData(any)
}

type Response

type Response struct {
	Success    bool               `json:"success"`
	Duration   int64              `json:"duration"`
	Pagination models.IPagination `json:"pagination,omitempty"`
	Error      IError             `json:"error,omitempty"`
	Data       any                `json:"data,omitempty"`
}

func (*Response) GetData

func (r *Response) GetData() any

func (*Response) GetDuration

func (r *Response) GetDuration() int64

func (*Response) GetError

func (r *Response) GetError() IError

func (*Response) GetPagination

func (r *Response) GetPagination() models.IPagination

func (*Response) GetSuccess

func (r *Response) GetSuccess() bool

func (*Response) SetData

func (r *Response) SetData(data any)

func (*Response) SetDuration

func (r *Response) SetDuration(duration int64)

func (*Response) SetError

func (r *Response) SetError(err IError)

func (*Response) SetPagination

func (r *Response) SetPagination(pagination models.IPagination)

func (*Response) SetSuccess

func (r *Response) SetSuccess(success bool)

type Service

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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