Documentation ¶
Index ¶
- func CORSMiddleware() gin.HandlerFunc
- func ConfigTLS(certFile, keyFile string) *tls.Config
- func LogMiddleware(logger *zap.Logger) gin.HandlerFunc
- func RecoveryMiddleware(logger *zap.Logger, stack bool) gin.HandlerFunc
- func RequestIDMiddlewareFunc(c *gin.Context)
- func TimeoutMiddleware(duration time.Duration) gin.HandlerFunc
- type HTTPServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LogMiddleware ¶
func LogMiddleware(logger *zap.Logger) gin.HandlerFunc
LogMiddleware prints each request message
func RecoveryMiddleware ¶
func RecoveryMiddleware(logger *zap.Logger, stack bool) gin.HandlerFunc
RecoveryMiddleware returns a gin.HandlerFunc (middleware) that recovers from any panics and logs requests using uber-go/zap. All errors are logged using zap.Error(). stack means whether output the stack info. The stack info is easy to find where the error occurs but the stack info is too large.
func RequestIDMiddlewareFunc ¶
RequestIDMiddlewareFunc set the "X-Request-Id" for each request, let's you trace each request
func TimeoutMiddleware ¶
func TimeoutMiddleware(duration time.Duration) gin.HandlerFunc
TimeoutMiddleware limits the time for every request
Types ¶
type HTTPServer ¶
type HTTPServer struct { Addr string TLSConfig *tls.Config RouterHandler func(router *gin.Engine) EnableCompress bool EnableProxyHeaders bool EnablePrometheusMetrics bool EnablePProf bool EnableCORS bool }
HTTPServer defines an HTTP server
func (*HTTPServer) ListenAndServe ¶
func (hs *HTTPServer) ListenAndServe() error
ListenAndServe serves the HTTP requests and listens a net interface
Click to show internal directories.
Click to hide internal directories.