gctx

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	*gin.Context
}

Context 是对 gin.Context 的增强封装 提供了更便捷的参数获取和类型转换方法

func (*Context) Cookie

func (c *Context) Cookie(key string) Value

Cookie 获取 Cookie 值

func (*Context) Error

func (c *Context) Error(code int, msg string)

Error 返回错误响应

func (*Context) EventStream

func (c *Context) EventStream() chan []byte

EventStream 返回一个用于 Server-Sent Events 的通道 用于实现服务器推送功能 注意:调用者需要在完成后关闭返回的 channel

func (*Context) Header

func (c *Context) Header(key string) Value

Header 获取请求头

func (*Context) JSON

func (c *Context) JSON(code int, obj any)

JSON 返回 JSON 响应

func (*Context) Param

func (c *Context) Param(key string) Value

Param 获取路径参数

func (*Context) Query

func (c *Context) Query(key string) Value

Query 获取查询参数

func (*Context) SetUserId

func (c *Context) SetUserId(userId string)

SetUserId 设置用户 ID 到上下文

func (*Context) Success

func (c *Context) Success(data any)

Success 返回成功响应

func (*Context) UserId

func (c *Context) UserId() string

UserId 从上下文中获取用户 ID 通常由认证中间件设置

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value 封装了值和错误,支持链式类型转换

func (Value) Bool

func (v Value) Bool() (bool, error)

Bool 将值转换为 bool

func (Value) BoolOr

func (v Value) BoolOr(defaultVal bool) bool

BoolOr 将值转换为 bool,如果失败则返回默认值

func (Value) Int

func (v Value) Int() (int, error)

Int 将值转换为 int

func (Value) Int64

func (v Value) Int64() (int64, error)

Int64 将值转换为 int64

func (Value) Int64Or

func (v Value) Int64Or(defaultVal int64) int64

Int64Or 将值转换为 int64,如果失败则返回默认值

func (Value) IntOr

func (v Value) IntOr(defaultVal int) int

IntOr 将值转换为 int,如果失败则返回默认值

func (Value) String

func (v Value) String() (string, error)

String 返回字符串值

func (Value) StringOr

func (v Value) StringOr(defaultVal string) string

StringOr 返回字符串值,如果有错误则返回默认值

Jump to

Keyboard shortcuts

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