Documentation ¶
Index ¶
- func ApiLog(svcCtx *svc.ServiceContext) gin.HandlerFunc
- func Cors(svcCtx *svc.ServiceContext) gin.HandlerFunc
- func Logger(svcCtx *svc.ServiceContext) gin.HandlerFunc
- func LoggerWithConfig(conf LoggerConfig) gin.HandlerFunc
- func Tracing(svcCtx *svc.ServiceContext) gin.HandlerFunc
- type LogFormatter
- type LogFormatterParams
- type LoggerConfig
- type WithCodeResponseWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApiLog ¶
func ApiLog(svcCtx *svc.ServiceContext) gin.HandlerFunc
func Cors ¶
func Cors(svcCtx *svc.ServiceContext) gin.HandlerFunc
func Logger ¶
func Logger(svcCtx *svc.ServiceContext) 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 Tracing ¶
func Tracing(svcCtx *svc.ServiceContext) 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 // contains filtered or unexported fields }
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 // SkipPaths is an url path array which logs are not written. // Optional. SkipPaths []string }
LoggerConfig defines the config for Logger middleware.
type WithCodeResponseWriter ¶
type WithCodeResponseWriter struct { gin.ResponseWriter Code int }
A WithCodeResponseWriter is a helper to delay sealing a http.ResponseWriter on writing code.
func (*WithCodeResponseWriter) Flush ¶
func (w *WithCodeResponseWriter) Flush()
Flush flushes the response writer.
func (*WithCodeResponseWriter) Header ¶
func (w *WithCodeResponseWriter) Header() http.Header
Header returns the http header.
func (*WithCodeResponseWriter) Hijack ¶
func (w *WithCodeResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack implements the http.Hijacker interface. This expands the Response to fulfill http.Hijacker if the underlying http.ResponseWriter supports it.
func (*WithCodeResponseWriter) Write ¶
func (w *WithCodeResponseWriter) Write(bytes []byte) (int, error)
Write writes bytes into w.
func (*WithCodeResponseWriter) WriteHeader ¶
func (w *WithCodeResponseWriter) WriteHeader(code int)
WriteHeader writes code into w, and not sealing the writer.