middleware

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: MIT Imports: 11 Imported by: 0

README

Here are a few example middlewares for natsmicromw. The middlewares are:

  • requestid.go: Request ID middleware that parses the header for a request id (storing it into the request context), or generates a unique ID for each request using the header tag 'request_id' or a specified header tag.
  • metrics.go: Metrics middleware that collects Prometheus metrics for NATS messages including the total number of messages received, duration of requests, and size of payloads.
  • compression.go: Middleware that supports both request and reply data compression based on specific headers.

Documentation

Index

Constants

View Source
const (
	CompressionNone    CompressionType = ""
	CompressionGzip    CompressionType = "gzip"
	CompressionDeflate CompressionType = "deflate"

	HeaderAcceptEncoding string = "accept-encoding"
	HeaderEncoding              = "encoding"
)

Variables

View Source
var (
	ErrUnsupportedEncoding = errors.New("unsupported encoding")
)

Functions

func CompressionMiddleware added in v0.1.0

func CompressionMiddleware(next natsmicromw.MicroHandlerFunc) natsmicromw.MicroHandlerFunc

func GetCompressMin added in v0.1.0

func GetCompressMin() int

GetCompressMin retrieves the current global minimum size for compression.

func MetricsContextMiddleware added in v0.0.3

func MetricsContextMiddleware(next natsmicromw.ContextHandlerFunc) natsmicromw.ContextHandlerFunc

Same middleware but with context support

func MetricsMicroMiddleware added in v0.1.0

func MetricsMicroMiddleware(next natsmicromw.MicroHandlerFunc) natsmicromw.MicroHandlerFunc

One more version for `MicroRequest` and `MicroReply`

func MetricsMiddleware

func MetricsMiddleware(next micro.Handler) micro.Handler

Middleware that increments the message count metric

func RequestIdFromContext

func RequestIdFromContext(ctx context.Context) string

Get current request Id from the context

func RequestIdMicroMiddleware added in v0.1.0

func RequestIdMicroMiddleware(tags ...string) func(next natsmicromw.MicroHandlerFunc) natsmicromw.MicroHandlerFunc

Same example with `MicroRequest` and `MicroReply`

func RequestIdMiddleware

func RequestIdMiddleware(tags ...string) func(next natsmicromw.ContextHandlerFunc) natsmicromw.ContextHandlerFunc

An example request id middleware

func SetCompressMin added in v0.1.0

func SetCompressMin(minBytes int)

SetCompressMin sets the global minimum size for compression.

Types

type CompressionType added in v0.1.0

type CompressionType string

Jump to

Keyboard shortcuts

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