Documentation
¶
Index ¶
- Constants
- type Context
- func (ctx *Context) Abort()
- func (ctx *Context) AbortWithStatus(code int)
- func (ctx *Context) Bind(obj any) error
- func (ctx *Context) ClientIP() string
- func (ctx *Context) ContentType() string
- func (ctx *Context) Context() context.Context
- func (ctx *Context) Cookie(name string) string
- func (ctx *Context) Data(code int, contentType string, data []byte)
- func (ctx *Context) Error(err error)
- func (ctx *Context) File(filepath string)
- func (ctx *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (ctx *Context) FullPath() string
- func (ctx *Context) GetHeader(key string) string
- func (ctx *Context) GetRawData() []byte
- func (ctx *Context) GetResponseHeader(key string) string
- func (ctx *Context) GetUserID() uint64
- func (ctx *Context) GetUserValue(key string) (value any, exists bool)
- func (ctx *Context) HTML(code int, name string, obj any)
- func (ctx *Context) IsAborted() bool
- func (ctx *Context) IsWebsocket() bool
- func (ctx *Context) JSON(code int, obj any)
- func (ctx *Context) Method() string
- func (ctx *Context) Param(key string) string
- func (ctx *Context) Path() string
- func (ctx *Context) PostForm(key string) string
- func (ctx *Context) Query(key string) string
- func (ctx *Context) Redirect(code int, location string)
- func (ctx *Context) RequestBody() []byte
- func (ctx *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
- func (ctx *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
- func (ctx *Context) SetCookieKV(key, value string)
- func (ctx *Context) SetHeader(key, value string)
- func (ctx *Context) SetStatusCode(statusCode int)
- func (ctx *Context) SetUserValue(key string, value any)
- func (ctx *Context) Status(code int)
- func (ctx *Context) String(code int, format string, values ...any)
- func (ctx *Context) Write(data []byte) (int, error)
- func (ctx *Context) WriteString(s string) (int, error)
- type Response
- func BusinessError(message ...any) *Response
- func Conflict(message any) *Response
- func DatabaseError(message any) *Response
- func InternalError(message ...any) *Response
- func NoContent() *Response
- func NotFound(message any) *Response
- func PageSuccess(data any, total int64) *Response
- func ParamError(message any) *Response
- func PaymentError(message any) *Response
- func RateLimit(message any) *Response
- func Success(data any) *Response
- func SystemError(message any) *Response
- func ThirdPartyError(serviceName string, message any) *Response
- func Unauthorized(message any) *Response
Constants ¶
View Source
const ( SUCCESS_OK = 100000 // 操作成功 SUCCESS_NO_CONTENT = 100001 // 成功但无返回内容 SUCCESS_ACCEPTED = 100002 // 请求已接受 SUCCESS_PARTIAL_CONTENT = 100003 // 部分内容 )
成功类
View Source
const ( CLIENT_PARAM_ERROR = 200001 // 参数错误 CLIENT_NOT_FOUND = 200002 // 资源不存在 CLIENT_UNAUTHORIZED = 200003 // 未认证 CLIENT_FORBIDDEN = 200004 // 禁止访问 CLIENT_CONFLICT = 200005 // 资源冲突 CLIENT_TOO_MANY_REQUESTS = 200006 // 请求频率过高 CLIENT_INVALID_TOKEN = 200007 // 无效令牌 CLIENT_TOKEN_EXPIRED = 200008 // 令牌过期 CLIENT_UNSUPPORTED_MEDIA = 200009 // 不支持的媒体类型 CLIENT_VALIDATION_FAILED = 200010 // 数据验证失败 CLIENT_MISSING_HEADER = 200011 // 缺少必要请求头 CLIENT_INVALID_FORMAT = 200012 // 格式错误 )
客户端错误类
View Source
const ( SERVER_INTERNAL_ERROR = 300001 // 服务端内部错误 SERVER_DATABASE_ERROR = 300002 // 数据库操作失败 SERVER_REDIS_ERROR = 300003 // Redis 操作失败 SERVER_RATE_LIMIT = 300004 // 接口限流 SERVER_SERVICE_UNAVAILABLE = 300005 // 服务不可用 SERVER_TIMEOUT = 300006 // 操作超时 SERVER_CONFIG_ERROR = 300007 // 配置错误 SERVER_INIT_FAILED = 300008 // 初始化失败 BUSINESS_ERROR = 310000 // 业务错误 )
服务端错误类
View Source
const ( THIRD_PARTY_ERROR = 400001 // 第三方服务错误 THIRD_PARTY_PAYMENT_ERROR = 400002 // 支付服务错误 THIRD_PARTY_SMS_ERROR = 400003 // 短信服务错误 THIRD_PARTY_EMAIL_ERROR = 400004 // 邮件服务错误 THIRD_PARTY_STORAGE_ERROR = 400005 // 存储服务错误 THIRD_PARTY_API_ERROR = 400006 // API调用错误 )
第三方服务错误类
View Source
const ( SYSTEM_ERROR = 500001 // 系统错误 SYSTEM_RESOURCE_EXHAUSTED = 500002 // 资源耗尽 SYSTEM_FILE_NOT_FOUND = 500003 // 文件不存在 SYSTEM_PERMISSION_DENIED = 500004 // 权限不足 )
系统错误类
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
*app.RequestContext
// contains filtered or unexported fields
}
Context 是对 Hertz 的 app.RequestContext 的封装
func NewContext ¶
func NewContext(ctx context.Context, c *app.RequestContext) *Context
NewContext 创建一个新的 Context
func (*Context) AbortWithStatus ¶
AbortWithStatus 调用 Abort 并写入指定的状态码
func (*Context) ContentType ¶
ContentType 返回请求的 Content-Type 头
func (*Context) FormFile ¶
func (ctx *Context) FormFile(name string) (*multipart.FileHeader, error)
FormFile 返回指定表单键的第一个文件
func (*Context) GetResponseHeader ¶
GetResponseHeader 获取响应头
func (*Context) GetUserValue ¶
GetUserValue 从用户值中获取指定键的值
func (*Context) IsWebsocket ¶
IsWebsocket 如果请求头表明客户端正在发起 websocket 握手,则返回 true
func (*Context) SaveUploadedFile ¶
func (ctx *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
SaveUploadedFile 将上传的文件保存到指定目标
func (*Context) SetCookie ¶
func (ctx *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
SetCookie 添加一个 Set-Cookie 头到响应头中
func (*Context) SetCookieKV ¶
SetCookieKV 设置 cookie(简化版)
func (*Context) SetStatusCode ¶
SetStatusCode 设置响应状态码
func (*Context) SetUserValue ¶
SetUserValue 设置用户值
type Response ¶
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data"`
}
func BusinessError ¶
func DatabaseError ¶
func PageSuccess ¶
func PaymentError ¶
func Unauthorized ¶
Click to show internal directories.
Click to hide internal directories.