Documentation
¶
Index ¶
- func Error(c *gin.Context, code int, message string)
- func ErrorWithStatus(c *gin.Context, httpStatus int, code int, message string)
- func Success(c *gin.Context, data interface{})
- type Logger
- type LoggerAdapter
- type MetricData
- type MetricRecorder
- type Mode
- type Option
- func WithCORS() Option
- func WithLogger(logger Logger) Option
- func WithMaxBodyLogSize(size int64) Option
- func WithMaxMultipartMemory(size int64) Option
- func WithMetric(recorder MetricRecorder) Option
- func WithMiddleware(middlewares ...gin.HandlerFunc) Option
- func WithMode(mode Mode) Option
- func WithPrettyJSON() Option
- func WithRecover() Option
- func WithServiceName(name string) Option
- func WithSkipPaths(paths ...string) Option
- func WithSlowRequestThreshold(duration time.Duration) Option
- func WithTrace() Option
- type Response
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorWithStatus ¶
ErrorWithStatus 带 HTTP 状态码的错误响应
Types ¶
type Logger ¶
type Logger interface {
// Info 信息日志
Info(ctx context.Context, msg string, fields map[string]interface{})
// Warn 警告日志
Warn(ctx context.Context, msg string, fields map[string]interface{})
// Error 错误日志
Error(ctx context.Context, msg string, fields map[string]interface{})
}
Logger 日志接口
func NewLoggerAdapter ¶
NewLoggerAdapter 创建新的 logger 适配器
type LoggerAdapter ¶
type LoggerAdapter struct {
// contains filtered or unexported fields
}
LoggerAdapter 将 kit/logger.Logger 适配到 web.Logger 接口
func (*LoggerAdapter) Error ¶
func (a *LoggerAdapter) Error(ctx context.Context, msg string, fields map[string]interface{})
Error 记录 error 级别日志
type MetricData ¶
MetricData 指标数据
type MetricRecorder ¶
type MetricRecorder interface {
// RecordRequest 记录请求指标
RecordRequest(data MetricData)
}
MetricRecorder 指标记录器接口
type Option ¶
type Option func(*options)
Option 配置选项
func WithMaxBodyLogSize ¶
WithMaxBodyLogSize 设置最大 body 日志大小
func WithMaxMultipartMemory ¶
WithMaxMultipartMemory 设置最大文件上传内存
func WithMiddleware ¶
func WithMiddleware(middlewares ...gin.HandlerFunc) Option
WithMiddleware 添加自定义中间件
func WithSlowRequestThreshold ¶
WithSlowRequestThreshold 设置慢请求阈值
type Response ¶
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
Response 统一响应结构
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server Gin 服务器封装
func (*Server) RunWithGracefulShutdown ¶
RunWithGracefulShutdown 启动服务器并支持优雅关闭
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
01_basic
command
|
|
|
02_with_trace
command
|
|
|
03_with_metric
command
|
|
|
04_file_upload
command
|
|
|
05_custom_logger
command
|
|
|
06_production
command
|
|
|
07_with_signoz
command
|
|
|
08_with_kit_logger
command
|
Click to show internal directories.
Click to hide internal directories.