Documentation ¶
Index ¶
- Variables
- func Extract(ctx context.Context, req *http.Request, opts ...Option) ([]attribute.KeyValue, baggage.Baggage, trace.SpanContext)
- func ExtractBookStockRequestPayload(r *http.Request) (bookStock *dto.BookStockRequestDTO, e error)
- func FromJSON(i interface{}, r io.Reader) error
- func Inject(ctx context.Context, req *http.Request, opts ...Option)
- func MetricsMiddleware(next http.Handler) http.Handler
- func ToJSON(i interface{}, w io.Writer) error
- type Option
- type Validation
- type ValidationError
- type ValidationErrors
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
func Extract(ctx context.Context, req *http.Request, opts ...Option) ([]attribute.KeyValue, baggage.Baggage, trace.SpanContext)
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 ¶
FromJSON deserializes the object from JSON string in an io.Reader to the given interface
func MetricsMiddleware ¶
MetricsMiddleware writes increments request count and calculates request duration and writes to Prometheus metrics
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 (*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