Documentation ¶
Index ¶
- Variables
- func Cors(config config.CorsConfig) gin.HandlerFunc
- func Logger() gin.HandlerFunc
- func LoggerWithConfig(conf LoggerConfig) gin.HandlerFunc
- func Recovery() gin.HandlerFunc
- func RecoveryWithWriter(out io.Writer) gin.HandlerFunc
- func Tracer() gin.HandlerFunc
- type LogFormatter
- type LogFormatterParams
- type LoggerConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultErrorWriter io.Writer = os.Stderr
DefaultErrorWriter is the default io.Writer used by Gin to debug errors
Functions ¶
func Cors ¶
func Cors(config config.CorsConfig) gin.HandlerFunc
func Logger ¶
func Logger() gin.HandlerFunc
Logger instances a Logger middleware that will write the logs to gin.DefaultWriter. By default, gin.DefaultWriter = os.Stdout.
func LoggerWithConfig ¶
func LoggerWithConfig(conf LoggerConfig) gin.HandlerFunc
LoggerWithConfig instance a Logger middleware with config.
func Recovery ¶
func Recovery() gin.HandlerFunc
func RecoveryWithWriter ¶
func RecoveryWithWriter(out io.Writer) gin.HandlerFunc
RecoveryWithWriter returns a middleware for a given writer that recovers from any panics and writes a 500 if there was one.
func Tracer ¶
func Tracer() gin.HandlerFunc
Types ¶
type LogFormatter ¶
type LogFormatter func(params LogFormatterParams) string
LogFormatter gives the signature of the formatter function passed to LoggerWithFormatter
type LogFormatterParams ¶
type LogFormatterParams struct { Request *http.Request // TimeStamp shows the time after the server returns a response. TimeStamp time.Time // StatusCode is HTTP response code. StatusCode int // Latency is how much time the server cost to process a certain request. Latency time.Duration // ClientIP equals Context's ClientIP method. ClientIP string // Method is the HTTP method given to the request. Method string // Path is a path the client requests. Path string // ErrorMessage is set if error has occurred in processing the request. ErrorMessage string // BodySize is the size of the Response Body BodySize int // Keys are the keys set on the request's context. Keys map[string]any }
LogFormatterParams is the structure any formatter will be handed when time to log comes
type LoggerConfig ¶
type LoggerConfig struct { // Optional. Default value is gin.defaultLogFormatter Formatter LogFormatter // Output is a writer where logs are written. // Optional. Default value is gin.DefaultWriter. Output io.Writer // SkipPaths is an url path array which logs are not written. // Optional. SkipPaths []string }
LoggerConfig defines the config for Logger middleware.
Click to show internal directories.
Click to hide internal directories.