Documentation
¶
Index ¶
- Constants
- func DisableBindValidation()
- func EnableJsonDecoderDisallowUnknownFields()
- func EnableJsonDecoderUseNumber()
- func SetMode(value string)
- type BasicHandler
- type Cache
- func NewCache[K comparable, V any](defaultExpiration, cleanupInterval time.Duration) *Cache[K, V]
- func SetGlobalCache(defaultExpiration, cleanupInterval time.Duration) *Cache[string, any]
- func SetGlobalCacheWithPersistence(defaultExpiration, cleanupInterval time.Duration, persistPath string, ...) *Cache[string, any]
- func (c *Cache[K, V]) BLPop(key K, timeout time.Duration) (V, bool)
- func (c *Cache[K, V]) BRPop(key K, timeout time.Duration) (V, bool)
- func (c *Cache[K, V]) BRPopLPush(source K, destination K, timeout time.Duration) (V, bool)
- func (c *Cache[K, V]) BeginTransaction() *Transaction[K, V]
- func (c *Cache[K, V]) Clear()
- func (c *Cache[K, V]) Close()
- func (c *Cache[K, V]) Count() int
- func (c *Cache[K, V]) Dec(key K, decrement any) (any, error)
- func (c *Cache[K, V]) DecAtomic(key K, n int64) (int64, error)
- func (c *Cache[K, V]) Delete(key K)
- func (c *Cache[K, V]) DeleteExpired()
- func (c *Cache[K, V]) DeleteList(key K)
- func (c *Cache[K, V]) DisableAutoPersist()
- func (c *Cache[K, V]) EnableAutoPersist()
- func (c *Cache[K, V]) Flush() error
- func (c *Cache[K, V]) ForEach(fn func(key K, value V) bool)
- func (c *Cache[K, V]) ForEachList(fn func(key K, list []V) bool)
- func (c *Cache[K, V]) Get(key K) (V, bool)
- func (c *Cache[K, V]) GetListTTL(key K) (time.Duration, bool)
- func (c *Cache[K, V]) GetStats() Stats
- func (c *Cache[K, V]) GetTTL(key K) (time.Duration, bool)
- func (c *Cache[K, V]) GetWithTTL(key K) (V, time.Duration, bool)
- func (c *Cache[K, V]) Has(key K) bool
- func (c *Cache[K, V]) HasList(key K) bool
- func (c *Cache[K, V]) Inc(key K, increment any) (any, error)
- func (c *Cache[K, V]) IncAtomic(key K, n int64) (int64, error)
- func (c *Cache[K, V]) Keys() []K
- func (c *Cache[K, V]) LIndex(key K, index int) (V, bool)
- func (c *Cache[K, V]) LInsert(key K, before bool, pivot V, value V, equals func(a, b V) bool) int
- func (c *Cache[K, V]) LPop(key K) (V, bool)
- func (c *Cache[K, V]) LPush(key K, values ...V) int
- func (c *Cache[K, V]) LRange(key K, start, stop int) []V
- func (c *Cache[K, V]) LRem(key K, count int, value V, equals func(a, b V) bool) int
- func (c *Cache[K, V]) LSet(key K, index int, value V) bool
- func (c *Cache[K, V]) LTrim(key K, start, stop int) bool
- func (c *Cache[K, V]) ListCount() int
- func (c *Cache[K, V]) ListKeys() []K
- func (c *Cache[K, V]) Load() error
- func (c *Cache[K, V]) LoadOrInit() error
- func (c *Cache[K, V]) RPop(key K) (V, bool)
- func (c *Cache[K, V]) RPoplPush(source K, destination K) (V, bool)
- func (c *Cache[K, V]) RPush(key K, values ...V) int
- func (c *Cache[K, V]) Save() error
- func (c *Cache[K, V]) Set(key K, value V, duration ...time.Duration)
- func (c *Cache[K, V]) SetList(key K, duration ...time.Duration)
- func (c *Cache[K, V]) WithPersistence(persistPath string, autoPersistInterval time.Duration) *Cache[K, V]
- type Context
- func (c *Context) AllowCORS()
- func (c *Context) BaseURL() string
- func (c *Context) BindAndValidate(obj interface{}) bool
- func (c *Context) BindForm(obj interface{}) bool
- func (c *Context) BindHeader(obj interface{}) bool
- func (c *Context) BindJSON(obj interface{}) bool
- func (c *Context) BindQuery(obj interface{}) bool
- func (c *Context) BindUri(obj interface{}) bool
- func (c *Context) BuildUrl(path string) *urlBuilder
- func (c *Context) Cache(seconds int)
- func (c *Context) CacheClear()
- func (c *Context) CacheDelete(key string)
- func (c *Context) CacheDeleteList(key string)
- func (c *Context) CacheGet(key string) (any, bool)
- func (c *Context) CacheGetBool(key string) (bool, bool)
- func (c *Context) CacheGetFloat64(key string) (float64, bool)
- func (c *Context) CacheGetInt(key string) (int, bool)
- func (c *Context) CacheGetString(key string) (string, bool)
- func (c *Context) CacheHas(key string) bool
- func (c *Context) CacheHasList(key string) bool
- func (c *Context) CacheKeys() []string
- func (c *Context) CacheLIndex(key string, index int) (any, bool)
- func (c *Context) CacheLPop(key string) (any, bool)
- func (c *Context) CacheLPush(key string, values ...any) int
- func (c *Context) CacheLRange(key string, start, stop int) []any
- func (c *Context) CacheRPop(key string) (any, bool)
- func (c *Context) CacheRPush(key string, values ...any) int
- func (c *Context) CacheSet(key string, value any, duration ...time.Duration)
- func (c *Context) CacheSetList(key string, duration ...time.Duration)
- func (c *Context) ClearJWT()
- func (c *Context) ContentType() string
- func (c *Context) CreateJWTSession(secretKey string, userID string, expiration time.Duration, ...) (string, error)
- func (c *Context) Domain() string
- func (c *Context) Download(filepath, filename string)
- func (c *Context) Dump() H
- func (c *Context) Error(msg string, url ...string)
- func (c *Context) Ext() string
- func (c *Context) Fail(msg string, url ...string)
- func (c *Context) FailWithData(msg string, data interface{}, url ...string)
- func (c *Context) Forbidden(msg string, url ...string)
- func (c *Context) GenerateJWT(secretKey string, payload JWTPayload) (string, error)
- func (c *Context) GetCache() *Cache[string, any]
- func (c *Context) GetIP() string
- func (c *Context) GetIntSlice(key string, sep ...string) []int
- func (c *Context) GetJWT() string
- func (c *Context) GetStringSlice(key string, sep ...string) []string
- func (c *Context) GetToken(name ...string) string
- func (c *Context) GetUserAgent() string
- func (c *Context) Host() string
- func (c *Context) IsAjax() bool
- func (c *Context) IsConnect() bool
- func (c *Context) IsDelete() bool
- func (c *Context) IsGet() bool
- func (c *Context) IsHead() bool
- func (c *Context) IsJson() bool
- func (c *Context) IsOptions() bool
- func (c *Context) IsPatch() bool
- func (c *Context) IsPjax() bool
- func (c *Context) IsPost() bool
- func (c *Context) IsPut() bool
- func (c *Context) IsSsl() bool
- func (c *Context) IsTrace() bool
- func (c *Context) Language() string
- func (c *Context) Method() string
- func (c *Context) MethodNotAllowed()
- func (c *Context) NewSSEClient(hub *SSEHub, filters ...string) *_SSEClient
- func (c *Context) NoCache()
- func (c *Context) NotFound(msg string, url ...string)
- func (c *Context) PageResponse(list any, totalCount int64, currentPage, pageSize int)
- func (c *Context) Paginate(defaultPageSize ...int) (page, pageSize int)
- func (c *Context) PanDomain() string
- func (c *Context) Param(param string, defaultValue ...string) string
- func (c *Context) ParamInt(param string, defaultValue ...int) int
- func (c *Context) ParseJWTPayload(token string) (JWTPayload, error)
- func (c *Context) Port() string
- func (c *Context) Protocol() string
- func (c *Context) Redirect(location string)
- func (c *Context) RedirectPermanent(location string)
- func (c *Context) RefreshJWTSession(secretKey string, expiration time.Duration) (string, error)
- func (c *Context) RemotePort() string
- func (c *Context) RequestInfo() H
- func (c *Context) RequireJWT(secretKey string) (JWTPayload, bool)
- func (c *Context) RequireParams(params ...string) bool
- func (c *Context) Response(httpStatus, code int, msg string, data interface{}, url ...string)
- func (c *Context) RootDomain() string
- func (c *Context) SaveUploadedFile(file *multipart.FileHeader, config UploadConfig) (string, error)
- func (c *Context) Scheme() string
- func (c *Context) ServiceUnavailable(msg string)
- func (c *Context) SessionGet(key string) (interface{}, bool)
- func (c *Context) SessionGetBool(key string) bool
- func (c *Context) SessionGetInt(key string) int
- func (c *Context) SessionGetString(key string) string
- func (c *Context) SessionSet(key string, value interface{})
- func (c *Context) SetCSP(policy string)
- func (c *Context) SetJWT(token string, maxAge int)
- func (c *Context) SetSecureHeaders()
- func (c *Context) SetXFrameOptions(option string)
- func (c *Context) SetXSSProtection()
- func (c *Context) StreamFile(filepath string)
- func (c *Context) SubDomain() string
- func (c *Context) Success(data interface{}, url ...string)
- func (c *Context) SuccessWithMsg(msg string, data interface{}, url ...string)
- func (c *Context) Time() time.Time
- func (c *Context) Type() string
- func (c *Context) URL() string
- func (c *Context) Unauthorized(msg string)
- func (c *Context) Validate(v Validator) bool
- func (c *Context) ValidateFile(file *multipart.FileHeader, config UploadConfig) error
- func (c *Context) ValidateJWT(secretKey string, token string) (JWTPayload, error)
- func (c *Context) ValidateWithCode(v Validator, code int) bool
- type H
- type Handler
- type HandlerFunc
- type HandlerWrapper
- type JWTPayload
- func (p JWTPayload) SetAudience(audience string) JWTPayload
- func (p JWTPayload) SetExpiresAt(expiresAt time.Time) JWTPayload
- func (p JWTPayload) SetIssuedAt(issuedAt time.Time) JWTPayload
- func (p JWTPayload) SetIssuer(issuer string) JWTPayload
- func (p JWTPayload) SetJWTID(jwtID string) JWTPayload
- func (p JWTPayload) SetNotBefore(notBefore time.Time) JWTPayload
- func (p JWTPayload) SetSubject(subject string) JWTPayload
- type ListResponse
- type Pagination
- type ResourceHandler
- type RestfulHandler
- type Router
- func (r *Router) ANY(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (r *Router) CONNECT(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (r *Router) DELETE(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (r *Router) Engine() *gin.Engine
- func (r *Router) GET(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (r *Router) Group(path string, middleware ...HandlerFunc) *RouterGroup
- func (r *Router) HEAD(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (r *Router) NewSSEHub(size ...int) *SSEHub
- func (r *Router) OPTIONS(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (r *Router) PATCH(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (r *Router) POST(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (r *Router) PUT(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (r *Router) Register(method, path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (r *Router) Resource(path string, handler ResourceHandler, middleware ...HandlerFunc)
- func (r *Router) Run(addr ...string) error
- func (r *Router) RunTLS(addr, certFile, keyFile string) error
- func (r *Router) RunWithConfig(config ServerConfig) error
- func (r *Router) TRACE(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (r *Router) Use(middleware ...HandlerFunc)
- func (r *Router) UseGin(middleware ...gin.HandlerFunc)
- type RouterGroup
- func (rg *RouterGroup) ANY(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (rg *RouterGroup) CONNECT(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (rg *RouterGroup) DELETE(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (rg *RouterGroup) GET(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (rg *RouterGroup) Group(path string, middleware ...HandlerFunc) *RouterGroup
- func (rg *RouterGroup) HEAD(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (rg *RouterGroup) OPTIONS(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (rg *RouterGroup) PATCH(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (rg *RouterGroup) POST(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (rg *RouterGroup) PUT(path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (rg *RouterGroup) Register(method, path string, handler HandlerFunc, middleware ...HandlerFunc)
- func (rg *RouterGroup) Resource(path string, handler ResourceHandler, middleware ...HandlerFunc)
- func (rg *RouterGroup) TRACE(path string, handler HandlerFunc, middleware ...HandlerFunc)
- type SSEEvent
- type SSEHub
- type ServerConfig
- type Stats
- type Transaction
- func (t *Transaction[K, V]) Commit()
- func (t *Transaction[K, V]) Delete(key K)
- func (t *Transaction[K, V]) DeleteList(key K)
- func (t *Transaction[K, V]) LPush(key K, values ...V)
- func (t *Transaction[K, V]) Rollback()
- func (t *Transaction[K, V]) Set(key K, value V, duration time.Duration)
- func (t *Transaction[K, V]) SetListExpiration(key K, duration time.Duration)
- type UploadConfig
- type Validator
Constants ¶
const ( SuccessCode = 200 // 成功状态码 FailCode = 400 // 失败状态码 ErrorCode = 500 // 错误状态码 ForbiddenCode = 403 // 禁止访问状态码 NotFound = 404 // 资源不存在状态码 )
const ( JWTHeaderKey = "Authorization" JWTQueryKey = "token" JWTCookieKey = "jwt" JWTPrefix = "Bearer " // JWT算法 JWTAlgHS256 = "HS256" // HMAC-SHA256 JWTAlgHS384 = "HS384" // HMAC-SHA384 JWTAlgHS512 = "HS512" // HMAC-SHA512 // JWT标准声明 JWTClaimIss = "iss" // 签发者 JWTClaimSub = "sub" // 主题 JWTClaimAud = "aud" // 受众 JWTClaimExp = "exp" // 过期时间 JWTClaimNbf = "nbf" // 生效时间 JWTClaimIat = "iat" // 签发时间 JWTClaimJti = "jti" // JWT ID )
JWT常量,保留公开因为它们是API契约的一部分
const ( MethodAny = "ANY" // 任意方法 MethodGet = "GET" // GET 请求 MethodHead = "HEAD" // HEAD 请求 MethodPost = "POST" // POST 请求 MethodPut = "PUT" // PUT 请求 MethodPatch = "PATCH" // PATCH 请求 (RFC 5789) MethodDelete = "DELETE" // DELETE 请求 MethodConnect = "CONNECT" // CONNECT 请求 MethodOptions = "OPTIONS" // OPTIONS 请求 MethodTrace = "TRACE" // TRACE 请求 )
常用 HTTP 方法常量
const ( EnvGinMode = "GIN_MODE" DebugMode = "debug" ReleaseMode = "release" TestMode = "test" )
Variables ¶
This section is empty.
Functions ¶
func EnableJsonDecoderDisallowUnknownFields ¶
func EnableJsonDecoderDisallowUnknownFields()
EnableJsonDecoderDisallowUnknownFields 设置 binding.EnableDecoderDisallowUnknownFields 为 true,以调用 JSON 解码器实例的 DisallowUnknownFields 方法。
func EnableJsonDecoderUseNumber ¶
func EnableJsonDecoderUseNumber()
EnableJsonDecoderUseNumber 设置 binding.EnableDecoderUseNumber 为 true,以调用 JSON 解码器实例的 UseNumber 方法。
Types ¶
type BasicHandler ¶
type BasicHandler struct {
Handlers map[string]HandlerFunc
}
BasicHandler 结构体用于存储处理函数
func NewBasicHandler ¶ added in v0.1.1
func NewBasicHandler() *BasicHandler
NewBasicHandler 创建一个新的基本处理器
func (*BasicHandler) GetHandler ¶
func (b *BasicHandler) GetHandler(action string) (HandlerFunc, bool)
GetHandler 方法根据动作获取处理函数 返回处理函数和是否找到的布尔值
func (*BasicHandler) SetHandler ¶
func (b *BasicHandler) SetHandler(action string, handlerFunc HandlerFunc)
SetHandler 方法用于设置处理函数
type Cache ¶ added in v0.1.2
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache 是一个综合的缓存实现,支持内存缓存和列表缓存
func NewCache ¶ added in v0.1.2
func NewCache[K comparable, V any](defaultExpiration, cleanupInterval time.Duration) *Cache[K, V]
NewCache 创建一个新的综合缓存 defaultExpiration: 默认的过期时间 cleanupInterval: 清理过期项的间隔时间
func SetGlobalCache ¶ added in v0.1.2
初始化全局缓存
func SetGlobalCacheWithPersistence ¶ added in v0.1.2
func SetGlobalCacheWithPersistence(defaultExpiration, cleanupInterval time.Duration, persistPath string, autoPersistInterval time.Duration) *Cache[string, any]
初始化带持久化的全局缓存
func (*Cache[K, V]) BRPopLPush ¶ added in v0.1.2
BRPopLPush 阻塞版本的RPoplPush timeout为等待时间,0表示无限等待
func (*Cache[K, V]) BeginTransaction ¶ added in v0.1.2
func (c *Cache[K, V]) BeginTransaction() *Transaction[K, V]
BeginTransaction 开始一个新事务
func (*Cache[K, V]) Close ¶ added in v0.1.2
func (c *Cache[K, V]) Close()
Close 停止清理过期项和自动持久化的goroutine
func (*Cache[K, V]) DeleteExpired ¶ added in v0.1.2
func (c *Cache[K, V]) DeleteExpired()
DeleteExpired 删除所有过期的项
func (*Cache[K, V]) DeleteList ¶ added in v0.1.2
func (c *Cache[K, V]) DeleteList(key K)
DeleteList 删除列表
func (*Cache[K, V]) DisableAutoPersist ¶ added in v0.1.2
func (c *Cache[K, V]) DisableAutoPersist()
DisableAutoPersist 禁用自动持久化
func (*Cache[K, V]) EnableAutoPersist ¶ added in v0.1.2
func (c *Cache[K, V]) EnableAutoPersist()
EnableAutoPersist 启用自动持久化
func (*Cache[K, V]) ForEachList ¶ added in v0.1.2
ForEachList 遍历所有未过期的列表
func (*Cache[K, V]) GetListTTL ¶ added in v0.1.2
GetListTTL 获取列表键的剩余生存时间
func (*Cache[K, V]) GetWithTTL ¶ added in v0.1.2
GetWithTTL 获取缓存项及其剩余生存时间
func (*Cache[K, V]) LInsert ¶ added in v0.1.2
LInsert 在列表的指定位置插入元素 before == true表示在pivot之前插入 before == false表示在pivot之后插入
func (*Cache[K, V]) ListKeys ¶ added in v0.1.2
func (c *Cache[K, V]) ListKeys() []K
ListKeys 返回所有的列表键
func (*Cache[K, V]) LoadOrInit ¶ added in v0.1.2
LoadOrInit 从文件加载缓存,如果文件不存在则初始化一个新的缓存
type Context ¶
func (*Context) BindAndValidate ¶ added in v0.1.1
BindAndValidate 绑定并验证请求数据
func (*Context) BindHeader ¶ added in v0.1.1
BindHeader 绑定Header参数并处理错误
func (*Context) CacheDeleteList ¶ added in v0.1.2
删除列表缓存
func (*Context) CacheGetBool ¶ added in v0.1.2
从缓存获取布尔值
func (*Context) CacheGetFloat64 ¶ added in v0.1.2
从缓存获取浮点值
func (*Context) CacheGetInt ¶ added in v0.1.2
从缓存获取整数值
func (*Context) CacheGetString ¶ added in v0.1.2
从缓存获取字符串值
func (*Context) CacheHasList ¶ added in v0.1.2
检查列表缓存是否存在
func (*Context) CacheLIndex ¶ added in v0.1.2
获取列表缓存指定索引的元素
func (*Context) CacheLPush ¶ added in v0.1.2
向列表缓存头部添加元素
func (*Context) CacheLRange ¶ added in v0.1.2
获取列表缓存的范围元素
func (*Context) CacheRPush ¶ added in v0.1.2
向列表缓存尾部添加元素
func (*Context) CacheSetList ¶ added in v0.1.2
设置列表缓存
func (*Context) ContentType ¶
ContentType 获取当前请求的CONTENT_TYPE
func (*Context) CreateJWTSession ¶ added in v0.1.1
func (c *Context) CreateJWTSession(secretKey string, userID string, expiration time.Duration, extraClaims ...map[string]interface{}) (string, error)
CreateJWTSession 使用JWT创建用户会话
func (*Context) FailWithData ¶
FailWithData 失败响应(带数据)
func (*Context) GenerateJWT ¶ added in v0.1.1
func (c *Context) GenerateJWT(secretKey string, payload JWTPayload) (string, error)
GenerateJWT 生成JWT令牌
func (*Context) GetIntSlice ¶ added in v0.1.1
GetIntSlice 获取整型切片
func (*Context) GetStringSlice ¶ added in v0.1.1
GetStringSlice 获取字符串切片
func (*Context) MethodNotAllowed ¶ added in v0.1.1
func (c *Context) MethodNotAllowed()
MethodNotAllowed 方法不允许响应
func (*Context) NewSSEClient ¶ added in v0.1.1
NewSSEClient 创建新的 SSE 客户端连接
func (*Context) PageResponse ¶
PageResponse 分页响应方法,适配新的结构体
func (*Context) ParseJWTPayload ¶ added in v0.1.1
func (c *Context) ParseJWTPayload(token string) (JWTPayload, error)
ParseJWTPayload 解析JWT载荷(不验证签名)
func (*Context) RedirectPermanent ¶
RedirectPermanent 永久重定向
func (*Context) RefreshJWTSession ¶ added in v0.1.1
RefreshJWTSession 刷新JWT会话
func (*Context) RequireJWT ¶ added in v0.1.1
func (c *Context) RequireJWT(secretKey string) (JWTPayload, bool)
RequireJWT 要求JWT令牌有效并返回载荷
func (*Context) RequireParams ¶
RequireParams 检查必需参数
func (*Context) SaveUploadedFile ¶
func (c *Context) SaveUploadedFile(file *multipart.FileHeader, config UploadConfig) (string, error)
SaveUploadedFile 保存上传文件
func (*Context) ServiceUnavailable ¶ added in v0.1.1
ServiceUnavailable 服务不可用响应
func (*Context) SessionGet ¶ added in v0.1.1
SessionGet 获取会话数据
func (*Context) SessionGetBool ¶ added in v0.1.1
SessionGetBool 获取布尔类型的会话数据
func (*Context) SessionGetInt ¶ added in v0.1.1
SessionGetInt 获取整数类型的会话数据
func (*Context) SessionGetString ¶ added in v0.1.1
SessionGetString 获取字符串类型的会话数据
func (*Context) SessionSet ¶ added in v0.1.1
SessionSet 设置会话数据
func (*Context) SetSecureHeaders ¶ added in v0.1.1
func (c *Context) SetSecureHeaders()
SetSecureHeaders 设置常用安全头
func (*Context) SetXFrameOptions ¶ added in v0.1.1
SetXFrameOptions 设置X-Frame-Options
func (*Context) SetXSSProtection ¶ added in v0.1.1
func (c *Context) SetXSSProtection()
SetXSSProtection 设置XSS保护
func (*Context) StreamFile ¶ added in v0.1.1
StreamFile 流式传输文件
func (*Context) SuccessWithMsg ¶
SuccessWithMsg 成功响应(自定义消息)
func (*Context) Unauthorized ¶ added in v0.1.1
Unauthorized 未授权响应
func (*Context) ValidateFile ¶
func (c *Context) ValidateFile(file *multipart.FileHeader, config UploadConfig) error
ValidateFile 验证上传文件
func (*Context) ValidateJWT ¶ added in v0.1.1
func (c *Context) ValidateJWT(secretKey string, token string) (JWTPayload, error)
ValidateJWT 验证JWT令牌
type Handler ¶
type Handler interface {
GetHandler(action string) (HandlerFunc, bool)
SetHandler(action string, handlerFunc HandlerFunc)
Clone() Handler
}
Handler 接口定义了处理程序的基本方法
type HandlerWrapper ¶ added in v0.1.1
type HandlerWrapper struct {
Handler Handler // 原始处理器
Middlewares []HandlerFunc // 中间件列表
Cache map[string]HandlerFunc // 中间件缓存
}
HandlerWrapper 封装了 Handler 便于添加中间件
func NewHandlerWrapper ¶ added in v0.1.1
func NewHandlerWrapper(handler Handler) *HandlerWrapper
NewHandlerWrapper 创建新的处理器包装器
func (*HandlerWrapper) Clone ¶ added in v0.1.1
func (hw *HandlerWrapper) Clone() Handler
Clone 克隆处理器包装器
func (*HandlerWrapper) GetHandler ¶ added in v0.1.1
func (hw *HandlerWrapper) GetHandler(action string) (HandlerFunc, bool)
GetHandler 获取添加了中间件的处理函数
func (*HandlerWrapper) SetHandler ¶ added in v0.1.1
func (hw *HandlerWrapper) SetHandler(action string, handlerFunc HandlerFunc)
SetHandler 设置处理函数
func (*HandlerWrapper) UseMiddleware ¶ added in v0.1.1
func (hw *HandlerWrapper) UseMiddleware(middlewares ...HandlerFunc)
UseMiddleware 添加中间件
type JWTPayload ¶ added in v0.1.1
type JWTPayload map[string]interface{}
JWTPayload JWT载荷(保留公开因为它是API的一部分)
func (JWTPayload) SetAudience ¶ added in v0.1.1
func (p JWTPayload) SetAudience(audience string) JWTPayload
func (JWTPayload) SetExpiresAt ¶ added in v0.1.1
func (p JWTPayload) SetExpiresAt(expiresAt time.Time) JWTPayload
func (JWTPayload) SetIssuedAt ¶ added in v0.1.1
func (p JWTPayload) SetIssuedAt(issuedAt time.Time) JWTPayload
func (JWTPayload) SetIssuer ¶ added in v0.1.1
func (p JWTPayload) SetIssuer(issuer string) JWTPayload
SetIssuer 设置JWT标准声明
func (JWTPayload) SetJWTID ¶ added in v0.1.1
func (p JWTPayload) SetJWTID(jwtID string) JWTPayload
func (JWTPayload) SetNotBefore ¶ added in v0.1.1
func (p JWTPayload) SetNotBefore(notBefore time.Time) JWTPayload
func (JWTPayload) SetSubject ¶ added in v0.1.1
func (p JWTPayload) SetSubject(subject string) JWTPayload
type ListResponse ¶ added in v0.1.1
type ListResponse struct {
Data any `json:"data"` // 数据列表,使用更通用的名称
Pagination Pagination `json:"pagination"` // 分页信息,使用更专业的命名
}
ListResponse 通用列表响应结构体
type Pagination ¶ added in v0.1.1
type Pagination struct {
CurrentPage int `json:"current_page"` // 当前页码,使用下划线风格的JSON标签
PageSize int `json:"page_size"` // 每页数量
TotalCount int64 `json:"total_count"` // 总数据量,使用更准确的命名
TotalPages int `json:"total_pages,omitempty"` // 总页数(可选)
}
Pagination 分页信息结构体
type ResourceHandler ¶ added in v0.1.1
type ResourceHandler interface {
Index(*Context) // GET /resources - 列表
Show(*Context) // GET /resources/:id - 详情
Create(*Context) // POST /resources - 创建
Update(*Context) // PUT /resources/:id - 更新
Delete(*Context) // DELETE /resources/:id - 删除
}
ResourceHandler 定义资源处理器接口
type RestfulHandler ¶ added in v0.1.1
type RestfulHandler struct{}
RestfulHandler 提供 ResourceHandler 接口的默认实现
func (*RestfulHandler) Create ¶ added in v0.1.1
func (h *RestfulHandler) Create(c *Context)
func (*RestfulHandler) Delete ¶ added in v0.1.1
func (h *RestfulHandler) Delete(c *Context)
func (*RestfulHandler) Index ¶ added in v0.1.1
func (h *RestfulHandler) Index(c *Context)
func (*RestfulHandler) Show ¶ added in v0.1.1
func (h *RestfulHandler) Show(c *Context)
func (*RestfulHandler) Update ¶ added in v0.1.1
func (h *RestfulHandler) Update(c *Context)
type Router ¶ added in v0.1.1
type Router struct {
// contains filtered or unexported fields
}
Router 路由管理器
func (*Router) ANY ¶ added in v0.1.1
func (r *Router) ANY(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*Router) CONNECT ¶ added in v0.1.1
func (r *Router) CONNECT(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*Router) DELETE ¶ added in v0.1.1
func (r *Router) DELETE(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*Router) GET ¶ added in v0.1.1
func (r *Router) GET(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*Router) Group ¶ added in v0.1.1
func (r *Router) Group(path string, middleware ...HandlerFunc) *RouterGroup
Group 创建或获取路由组
func (*Router) HEAD ¶ added in v0.1.1
func (r *Router) HEAD(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*Router) OPTIONS ¶ added in v0.1.1
func (r *Router) OPTIONS(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*Router) PATCH ¶ added in v0.1.1
func (r *Router) PATCH(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*Router) POST ¶ added in v0.1.1
func (r *Router) POST(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*Router) PUT ¶ added in v0.1.1
func (r *Router) PUT(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*Router) Register ¶ added in v0.1.1
func (r *Router) Register(method, path string, handler HandlerFunc, middleware ...HandlerFunc)
Register 注册路由
func (*Router) Resource ¶ added in v0.1.1
func (r *Router) Resource(path string, handler ResourceHandler, middleware ...HandlerFunc)
Resource 注册 RESTful 资源路由
func (*Router) RunWithConfig ¶ added in v0.1.1
func (r *Router) RunWithConfig(config ServerConfig) error
RunWithConfig 使用配置运行服务器
func (*Router) TRACE ¶ added in v0.1.1
func (r *Router) TRACE(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*Router) UseGin ¶ added in v0.1.1
func (r *Router) UseGin(middleware ...gin.HandlerFunc)
UseGin 中间件 直接使用 gin.HandlerFunc
type RouterGroup ¶ added in v0.1.1
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup 路由组
func (*RouterGroup) ANY ¶ added in v0.1.1
func (rg *RouterGroup) ANY(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*RouterGroup) CONNECT ¶ added in v0.1.1
func (rg *RouterGroup) CONNECT(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*RouterGroup) DELETE ¶ added in v0.1.1
func (rg *RouterGroup) DELETE(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*RouterGroup) GET ¶ added in v0.1.1
func (rg *RouterGroup) GET(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*RouterGroup) Group ¶ added in v0.1.1
func (rg *RouterGroup) Group(path string, middleware ...HandlerFunc) *RouterGroup
Group 创建子路由组
func (*RouterGroup) HEAD ¶ added in v0.1.1
func (rg *RouterGroup) HEAD(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*RouterGroup) OPTIONS ¶ added in v0.1.1
func (rg *RouterGroup) OPTIONS(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*RouterGroup) PATCH ¶ added in v0.1.1
func (rg *RouterGroup) PATCH(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*RouterGroup) POST ¶ added in v0.1.1
func (rg *RouterGroup) POST(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*RouterGroup) PUT ¶ added in v0.1.1
func (rg *RouterGroup) PUT(path string, handler HandlerFunc, middleware ...HandlerFunc)
func (*RouterGroup) Register ¶ added in v0.1.1
func (rg *RouterGroup) Register(method, path string, handler HandlerFunc, middleware ...HandlerFunc)
Register 注册路由到当前组
func (*RouterGroup) Resource ¶ added in v0.1.1
func (rg *RouterGroup) Resource(path string, handler ResourceHandler, middleware ...HandlerFunc)
Resource 注册路由组内的 RESTful 资源路由
func (*RouterGroup) TRACE ¶ added in v0.1.1
func (rg *RouterGroup) TRACE(path string, handler HandlerFunc, middleware ...HandlerFunc)
type SSEEvent ¶ added in v0.1.1
type SSEEvent struct {
Event string `json:"event"` // 事件名称
Data any `json:"data"` // 事件数据
ID string `json:"id"` // 事件ID
Retry int `json:"retry"` // 重试时间(毫秒)
}
SSEEvent SSE 事件结构体
type SSEHub ¶ added in v0.1.1
SSEHub SSE 连接管理中心
func (*SSEHub) GetClients ¶ added in v0.1.1
GetClients 获取所有在线客户端ID
type ServerConfig ¶ added in v0.1.1
type ServerConfig struct {
Host string // 主机地址
Port string // 端口
ReadTimeout time.Duration // 读取超时
WriteTimeout time.Duration // 写入超时
MaxHeaderBytes int // 最大头部字节
CertFile string // TLS证书文件
KeyFile string // TLS密钥文件
EnableHTTP2 bool // 启用HTTP/2
GracefulTimeout time.Duration // 优雅关闭超时
}
ServerConfig 服务器配置选项
func DefaultServerConfig ¶ added in v0.1.1
func DefaultServerConfig() ServerConfig
DefaultServerConfig 返回默认服务器配置
type Stats ¶ added in v0.1.2
type Stats struct {
ItemsCount int `json:"itemsCount"` // 普通缓存项数量
ListsCount int `json:"listsCount"` // 列表数量
HitCount uint64 `json:"hitCount"` // 命中次数
MissCount uint64 `json:"missCount"` // 未命中次数
LastSaveTime time.Time `json:"lastSaveTime"` // 最后一次保存时间
LastLoadTime time.Time `json:"lastLoadTime"` // 最后一次加载时间
CreationTime time.Time `json:"creationTime"` // 创建时间
MemoryUsage uint64 `json:"memoryUsage"` // 预估内存使用(字节)
ExpiredCount uint64 `json:"expiredCount"` // 过期项目计数
DeletedCount uint64 `json:"deletedCount"` // 删除项目计数
PersistPath string `json:"persistPath"` // 持久化路径
IsAutoPersist bool `json:"isAutoPersist"` // 是否开启自动持久化
SaveInterval time.Duration `json:"saveInterval"` // 保存间隔
}
Stats 缓存统计信息
type Transaction ¶ added in v0.1.2
type Transaction[K comparable, V any] struct { // contains filtered or unexported fields }
Transaction 表示一个缓存事务
func (*Transaction[K, V]) Delete ¶ added in v0.1.2
func (t *Transaction[K, V]) Delete(key K)
Delete 在事务中删除缓存项
func (*Transaction[K, V]) DeleteList ¶ added in v0.1.2
func (t *Transaction[K, V]) DeleteList(key K)
DeleteList 在事务中删除列表
func (*Transaction[K, V]) LPush ¶ added in v0.1.2
func (t *Transaction[K, V]) LPush(key K, values ...V)
LPush 在事务中将值插入列表头部
func (*Transaction[K, V]) Rollback ¶ added in v0.1.2
func (t *Transaction[K, V]) Rollback()
Rollback 回滚事务(什么也不做,因为事务只在Commit时才会应用)
func (*Transaction[K, V]) Set ¶ added in v0.1.2
func (t *Transaction[K, V]) Set(key K, value V, duration time.Duration)
Set 在事务中设置缓存项
func (*Transaction[K, V]) SetListExpiration ¶ added in v0.1.2
func (t *Transaction[K, V]) SetListExpiration(key K, duration time.Duration)
SetListExpiration 在事务中设置列表过期时间
type UploadConfig ¶
type UploadConfig struct {
AllowedExts []string // 允许的文件扩展名
MaxSize int64 // 最大文件大小(字节)
SavePath string // 保存路径
}
UploadConfig 文件上传相关方法