middleware

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessLog

func AccessLog(logger *AccessLogger) gin.HandlerFunc

func CORSMiddleware added in v0.1.9

func CORSMiddleware() gin.HandlerFunc

func CollectMetrics

func CollectMetrics(c *gin.Context)

func DynamicDebugLogging

func DynamicDebugLogging(c *gin.Context)

DynamicDebugLogging open the debug level logging in dynamically

func NewOpenTelemetryTracing

func NewOpenTelemetryTracing(serviceName string, propagator propagation.TextMapPropagator, tracerProvider oteltrace.TracerProvider) gin.HandlerFunc

NewOpenTelemetryTracing returns a Gin middleware function for tracing incoming requests. If no propagator or tracerProvider is provided, it uses the global ones.

func PanicRecovery

func PanicRecovery(logger *log.Logger) gin.HandlerFunc

PanicRecovery uses to catch panic in api handler

Types

type AccessLogger

type AccessLogger struct {
	IP string
	// contains filtered or unexported fields
}

func NewAccessLogger

func NewAccessLogger(writer io.Writer, pattern string) (*AccessLogger, error)

To set the enabled field as true by default to avoid the need for manual enabling of access log recording.

func (*AccessLogger) Disabled

func (accessLogger *AccessLogger) Disabled()

func (*AccessLogger) Enabled

func (accessLogger *AccessLogger) Enabled()

func (*AccessLogger) SetSlowRequestThreshold

func (accessLogger *AccessLogger) SetSlowRequestThreshold(duration time.Duration)

func (*AccessLogger) Status

func (accessLogger *AccessLogger) Status() string

type LogItem

type LogItem struct {
	TraceId        string
	ContentLength  int64
	URL            *url.URL
	RequestHeader  http.Header
	ResponseHeader http.Header
	RemoteAddr     string
	Method         string
	Proto          string
	ReceivedAt     time.Time
	FirstByteTime  time.Time
	Latency        time.Duration
	BytesSent      int
	StatusCode     int
}

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Hijacker
	http.Flusher

	Status() int              // Retrieve the status.
	Size() int                // Retrieve the size.
	FirstByteTime() time.Time // Retrieve the time of the first byte written.
}

ResponseWriter is an interface combining multiple http related interfaces, including http.ResponseWriter, http.Hijacker, and http.Flusher. It also provides additional methods to retrieve status, size and first byte time.

func NewResponseWriter

func NewResponseWriter(w http.ResponseWriter) ResponseWriter

Jump to

Keyboard shortcuts

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