Documentation ¶
Index ¶
- Constants
- func Cors(_ ...Option) gin.HandlerFunc
- func GetRequestId(c *gin.Context) string
- func Logger(conf LoggerConfig, whitelist []string) gin.HandlerFunc
- func RateLimiter(rate float64) gin.HandlerFunc
- func Recover() gin.HandlerFunc
- func RequestId() gin.HandlerFunc
- func SizeLimiter(size int64) gin.HandlerFunc
- func Timeout(timeout time.Duration, whitelist []string) gin.HandlerFunc
- type CustomResponseWriter
- type LogLinkField
- type LoggerConfig
- type Option
- type Options
- type SimpleBodyWriter
Constants ¶
View Source
const ( DefaultAllowOrigin = "*" DefaultAllowMethods = "*" DefaultAllowHeaders = "*" DefaultAllowCredentials = "*" DefaultExposeHeaders = "true" )
Variables ¶
This section is empty.
Functions ¶
func Cors ¶
func Cors(_ ...Option) gin.HandlerFunc
Cors @Description: 开启跨域控制 @Param ops: *Options 可选参数 可以设置跨域的配置 默认值为* 允许所有域名访问 允许所有请求方法 跨域允许所有请求头 允许跨域携带cookie @Return gin.HandlerFunc 返回一个gin.HandlerFunc 可以直接使用gin.Use(Cors()) 或者在路由中使用Cors() 即可 如果需要设置跨域的配置 可以使用 WithAllowOrigin WithAllowMethods WithAllowHeaders WithAllowCredentials WithExposeHeaders
func GetRequestId ¶
func Logger ¶
func Logger(conf LoggerConfig, whitelist []string) gin.HandlerFunc
func RateLimiter ¶
func RateLimiter(rate float64) gin.HandlerFunc
RateLimiter @Description: 请求速率限制 @return gin.HandlerFunc
func Recover ¶
func Recover() gin.HandlerFunc
func RequestId ¶
func RequestId() gin.HandlerFunc
func SizeLimiter ¶
func SizeLimiter(size int64) gin.HandlerFunc
SizeLimiter @Description: 请求体大小限制 @return gin.HandlerFunc
Types ¶
type CustomResponseWriter ¶
type CustomResponseWriter struct { gin.ResponseWriter // contains filtered or unexported fields }
func (CustomResponseWriter) WriteString ¶
func (w CustomResponseWriter) WriteString(s string) (int, error)
type LogLinkField ¶
type LoggerConfig ¶
type LoggerConfig struct { LogTag string `yaml:"log_tag" mapstructure:"log_tag"` MaxBody int `yaml:"max_body" mapstructure:"max_body"` MaxResponse int `yaml:"max_response" mapstructure:"max_response"` MaxFile uint `yaml:"max_file" mapstructure:"max_file"` Path string `yaml:"path" mapstructure:"path"` PrintThird bool `yaml:"print_third" mapstructure:"print_third"` }
type Options ¶
type Options struct { AllowOrigin string AllowMethods string AllowHeaders string AllowCredentials string ExposeHeaders string }
func WithAllowCredentials ¶
func WithAllowHeaders ¶
func WithAllowMethods ¶
func WithAllowOrigin ¶
func WithExposeHeaders ¶
type SimpleBodyWriter ¶
type SimpleBodyWriter struct { gin.ResponseWriter // contains filtered or unexported fields }
Click to show internal directories.
Click to hide internal directories.