gin

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HttpMethodGet     uint16 = 0b1
	HttpMethodHead    uint16 = 0b10
	HttpMethodPost    uint16 = 0b100
	HttpMethodPut     uint16 = 0b1000
	HttpMethodPatch   uint16 = 0b10000 // RFC 5789
	HttpMethodDelete  uint16 = 0b100000
	HttpMethodConnect uint16 = 0b1000000
	HttpMethodOptions uint16 = 0b10000000
	HttpMethodTrace   uint16 = 0b100000000
)
View Source
const SceneName = "scene.app-container.http.gin"

Variables

View Source
var (
	ErrAlreadyDone = errcode.CreateError(100, "gin already done")
)

Functions

func GetContext

func GetContext(c *gin.Context) scene.Context

func Handle

func Handle[A any, T Request[A]](app A, request T) gin.HandlerFunc

func HttpMethod added in v0.3.2

func HttpMethod(method string) uint16

HttpMethod convert http.Method to uint16 version

func MiddlewareChain

func MiddlewareChain(middlewares ...gin.HandlerFunc) func(handler gin.HandlerFunc) []gin.HandlerFunc

func NewAppContainer

func NewAppContainer(
	addr string,
	apps []GinApplication,
	options ...GinOption,
) scene.Scene

func NewAppContainerWithPrefix

func NewAppContainerWithPrefix(
	addr string,
	prefix string,
	apps []GinApplication,
	options ...GinOption,
) scene.Scene

func RequestWrapper added in v0.2.5

func RequestWrapper[T any](app T) func(Request[T]) gin.HandlerFunc

func WrapReq added in v0.2.5

func WrapReq[A any, T Request[A]](app A, request T) gin.HandlerFunc

Types

type Action added in v0.2.7

type Action[T any] interface {
	Request[T]
	HttpRoute
	Middleware() gin.HandlersChain
}

type AppRouter added in v0.2.7

type AppRouter[T any] struct {
	// contains filtered or unexported fields
}

func NewAppRouter added in v0.2.7

func NewAppRouter[T any](app T, router gin.IRouter) *AppRouter[T]

func (*AppRouter[T]) HandleAction added in v0.2.7

func (r *AppRouter[T]) HandleAction(action Action[T])

func (*AppRouter[T]) HandleActions added in v0.2.7

func (r *AppRouter[T]) HandleActions(actions ...Action[T])

func (*AppRouter[T]) Router added in v0.2.7

func (r *AppRouter[T]) Router() gin.IRouter

type AppRoutes added in v0.2.7

type AppRoutes[T any] struct {
	AppName  scene.ImplName
	BasePath string
	Actions  []Action[*T]
	Context  T
}

func (*AppRoutes[T]) Create added in v0.2.7

func (a *AppRoutes[T]) Create(engine *gin.Engine, router gin.IRouter) error

func (*AppRoutes[T]) Destroy added in v0.2.7

func (a *AppRoutes[T]) Destroy() error

func (*AppRoutes[T]) Name added in v0.2.7

func (a *AppRoutes[T]) Name() scene.ImplName

func (*AppRoutes[T]) Prefix added in v0.2.7

func (a *AppRoutes[T]) Prefix() string

type BaseAction added in v0.2.7

type BaseAction struct {
}

func (*BaseAction) Middleware added in v0.2.7

func (a *BaseAction) Middleware() gin.HandlersChain

type Context

type Context[T any] struct {
	*gin.Context
	App T // App is the container of current app
}

func (*Context[T]) Get

func (g *Context[T]) Get(key string) (value any, exists bool)

func (*Context[T]) Set

func (g *Context[T]) Set(key string, value any)

type GinApplication

type GinApplication interface {
	scene.Application
	Prefix() string
	Create(engine *gin.Engine, router gin.IRouter) error
	Destroy() error
}

type GinOption

type GinOption func(engine *gin.Engine) error

func WithCors

func WithCors() GinOption

func WithGzip added in v0.2.8

func WithGzip(level int) GinOption

WithGzip add gzip support for gin engine, default level is -1

func WithLogger

func WithLogger(log logger.ILogger) GinOption

func WithRecovery

func WithRecovery() GinOption

type HttpRoute added in v0.3.2

type HttpRoute interface {
	GetRoute() HttpRouteInfo
}

type HttpRouteInfo added in v0.3.2

type HttpRouteInfo struct {
	Method  string // Method specify a single method, might be deprecated in the future
	Methods uint16 // Methods aim to handle same route with multiple method
	Path    string // Path is gin router path
}

type ParameterBinder

type ParameterBinder[T any] interface {
	Bind(ctx *Context[T]) error
}

type Request

type Request[T any] interface {
	Process(ctx *Context[T]) (data any, err error)
	Binding() binding.Binding
}

type RequestForm added in v0.2.8

type RequestForm struct{}

func (*RequestForm) Binding added in v0.2.8

func (r *RequestForm) Binding() binding.Binding

type RequestFormUrlEncoded added in v0.2.8

type RequestFormUrlEncoded struct{}

func (*RequestFormUrlEncoded) Binding added in v0.2.8

func (r *RequestFormUrlEncoded) Binding() binding.Binding

type RequestJson

type RequestJson struct{}

func (*RequestJson) Binding

func (r *RequestJson) Binding() binding.Binding

type RequestNoParam added in v0.2.5

type RequestNoParam struct{}

func (*RequestNoParam) Binding added in v0.2.5

func (r *RequestNoParam) Binding() binding.Binding

type RequestQuery

type RequestQuery struct{}

func (*RequestQuery) Binding

func (r *RequestQuery) Binding() binding.Binding

type RequestURI

type RequestURI struct{}

func (*RequestURI) Binding

func (r *RequestURI) Binding() binding.Binding

Jump to

Keyboard shortcuts

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