httputils

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware() gin.HandlerFunc

CORSMiddleware middleware

func ConfigTLS

func ConfigTLS(certFile, keyFile string) *tls.Config

ConfigTLS configures the TCP TLS config with certificate and private key file

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

func RequestIDMiddlewareFunc(c *gin.Context)

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

func (*HTTPServer) Serve

func (hs *HTTPServer) Serve(l net.Listener) error

Serve just serves the HTTP requests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL