ginmw

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package ginmw offers a collection of middleware to enforce cross service policies, such as observabilities and context passing.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithContext

func WithContext() gin.HandlerFunc

WithContext is a gin middleware that adds request context to contract keys.

Example
g := gin.New()
g.Use(WithContext())
g.Handle("GET", "/", func(context *gin.Context) {
	context.String(200, "the request path is %s",
		context.Request.Context().Value(contract.RequestUrlKey))
})

func WithLogger

func WithLogger(logger log.Logger, keyer contract.Keyer, ignore ...string) gin.HandlerFunc

WithLogger is a gin middleware that logs access record via kitlog. The paths defined by "ignore" argument are ignored.

func WithMetrics

func WithMetrics(hist metrics.Histogram, keyer contract.Keyer, addPath bool) gin.HandlerFunc

WithMetrics is a gin middleware that adds request histogram. Setting addPath to true will make histogram to use request path as a dimension. This is ok with few total number of paths, but incurs performance issue if the cardinality of request path is high.

Example
g := gin.New()
g.Use(WithMetrics(prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
	Name: "request_duration_seconds",
	Help: "Total time spent serving requests.",
}, []string{"module", "method"}), key.New("module", "foo"), false))
g.Handle("GET", "/", func(context *gin.Context) {
	// Do stuff
})

func WithTrace

func WithTrace(tracer stdtracing.Tracer, keyer contract.Keyer) gin.HandlerFunc

WithTrace is a gin middleware that adds opentracing support.

Example
g := gin.New()
g.Use(WithTrace(opentracing.GlobalTracer(), key.New("module", "foo")))
g.Handle("GET", "/", func(context *gin.Context) {
	// Do stuff
})

Types

This section is empty.

Jump to

Keyboard shortcuts

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