middleware

package
v0.0.0-...-22f568f Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2022 License: MIT Imports: 13 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 ExtractAdddocumentPayload

func ExtractAdddocumentPayload(r *http.Request) (document *dto.DocumentRequestDTO, e error)

ExtractAdddocumentPayload extracts document data from the request body Returns documentRequestDTO 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 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 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