middleware

package
v0.0.0-...-f26ca9b Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package middleware is the package that holds the middleware logict for rest layer

Package middleware is the package that holds the middleware logict for rest layer

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 MetricsMiddleware

func MetricsMiddleware(next http.Handler) http.Handler

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

Types

type Validation

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

Validation contains the *validator.Validate instance

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

Error returns the error message for validation

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