Documentation
¶
Index ¶
- Constants
- func Cors() gin.HandlerFunc
- func GetGinContext(ctx context.Context) *gin.Context
- func GetLog(ctx context.Context) *log.SugaredLogger
- func GetRawData(ctx context.Context) []byte
- func GetRequestID(ctx context.Context) string
- func NewIPLimiter(r limiter.Limit, b int) func(next Handler) Handler
- func NewLog(appName string, showParams bool) func(next Handler) Handler
- func RegisterController(router IRoutes, ctls []any, hooks ...Hook)
- func RenderJSON(ctx context.Context, data *Return)
- func SetGinContext(ctx context.Context, c *gin.Context) context.Context
- type Code
- type Engine
- type Gin
- func (s *Gin) AdaptHandler(h Handler, hooks ...Hook) gin.HandlerFunc
- func (s *Gin) AddHook(hooks ...Hook)
- func (s *Gin) GetEngine() *Engine
- func (s *Gin) Host(host string) *Gin
- func (s *Gin) RegisterController(relativePath string, ctls []any, hooks ...Hook)
- func (s *Gin) Restart(ctx context.Context) error
- func (s *Gin) Start(ctx context.Context) error
- func (s *Gin) Stop(ctx context.Context) error
- type H
- type Handler
- type HandlerFunc
- type Hook
- type IRoutes
- type Return
Constants ¶
View Source
const ( RequestIDKey = "request_id" RawDataKey = "_yuan_RawData" )
Variables ¶
This section is empty.
Functions ¶
func GetGinContext ¶ added in v0.1.3
GetGinContext 从 context 中提取 *gin.Context。
func GetLog ¶ added in v0.1.3
func GetLog(ctx context.Context) *log.SugaredLogger
GetLog 从 context 中获取或创建请求级别的 logger。
func GetRawData ¶ added in v0.1.3
GetRawData 从 context 中读取并缓存原始请求 body。
func GetRequestID ¶ added in v0.1.3
GetRequestID 从 context 中获取或生成 request_id。
func NewIPLimiter ¶ added in v0.0.2
NewIPLimiter 创建基于客户端 IP 的令牌桶限流 Hook。
func RegisterController ¶ added in v0.0.2
RegisterController 扫描 ctls 的导出方法并注册为 GET/POST 路由。 方法签名要求: func(context.Context) (any, error)
func RenderJSON ¶ added in v0.1.3
RenderJSON 将 Return 响应信封写入 context 中关联的 gin.Context。
Types ¶
type Gin ¶
type Gin struct {
// contains filtered or unexported fields
}
func NewGinServer ¶
func NewGinServer() *Gin
func (*Gin) AdaptHandler ¶ added in v0.1.5
func (s *Gin) AdaptHandler(h Handler, hooks ...Hook) gin.HandlerFunc
AdaptHandler 将 Handler 适配为 gin.HandlerFunc,自动合并全局 hooks 与调用时传入的 hooks。
hooks 逆序包装,全局 hooks(s.hooks)在外层,调用时 hooks 在内层,与 RegisterController 行为一致。
func (*Gin) RegisterController ¶ added in v0.0.2
type Handler ¶
Handler 是业务处理函数的统一签名,接收 context.Context。 通过 GetGinContext(ctx) 获取原生 *gin.Context 进行参数绑定等操作。
type HandlerFunc ¶
type HandlerFunc = gin.HandlerFunc
Click to show internal directories.
Click to hide internal directories.