middleware

package
v0.0.0-...-0a0b1f3 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RequestCounterVec = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "http",
			Subsystem: "requests",
			Name:      "number_of_requests",
			Help:      "Total number of requests handled by the API",
		},
		[]string{"endpoint", "method"},
	)
)

RequestCounterVec counts total request per endpoint and method

View Source
var (
	RequestDurationGauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Namespace: "http",
			Subsystem: "requests",
			Name:      "request_duration",
			Help:      "Avg time of requests handled by the API",
		},
		[]string{"endpoint", "method"},
	)
)

RequestDurationGauge calculates avg time per endpoint and method

Functions

func Extract

Extract returns the Attributes, Context Entries, and SpanContext that were encoded by Inject.

func ExtractBookStockRequestPayload

func ExtractBookStockRequestPayload(r *http.Request) (bookStock *dto.BookStockRequestDTO, e error)

ExtractBookStockRequestPayload extracts bookStock data from the request body Returns bookStockRequestDTO model if found, error otherwise

func FromJSON

func FromJSON(i interface{}, r io.Reader) error

FromJSON deserializes the object from JSON string in an io.Reader to the given interface

func Inject

func Inject(ctx context.Context, req *http.Request, opts ...Option)

Inject sets attributes, context entries, and span context from ctx into the request.

func MetricsMiddleware

func MetricsMiddleware(next http.Handler) http.Handler

MetricsMiddleware writes increments request count and calculates request duration and writes to Prometheus metrics

func ToJSON

func ToJSON(i interface{}, w io.Writer) error

ToJSON serializes the given interface into a string based JSON format

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option allows configuration of the httptrace Extract() and Inject() functions.

func WithPropagators

func WithPropagators(props propagation.TextMapPropagator) Option

WithPropagators sets the propagators to use for Extraction and Injection.

type Validation

type Validation struct {
	// contains filtered or unexported fields
}

Validation contains

func NewValidation

func NewValidation() *Validation

NewValidation creates a new Validation type

func (*Validation) Validate

func (v *Validation) Validate(i interface{}) ValidationErrors

Validate validates the models

type ValidationError

type ValidationError struct {
	validator.FieldError
}

ValidationError wraps the validators FieldError so we do not expose this to out code

func (ValidationError) Error

func (v ValidationError) Error() string

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors is a collection of ValidationError

func (ValidationErrors) Errors

func (v ValidationErrors) Errors() []string

Errors converts the slice into a string slice

Jump to

Keyboard shortcuts

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