api

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLimitSize indicates that an invalid limit.
	ErrLimitSize = errors.New("invalid limit size")
	// ErrOffsetSize indicates an invalid offset.
	ErrOffsetSize = errors.New("invalid offset size")
	// ErrInvalidDateRange indicates date from and to are invalid.
	ErrInvalidDateRange = errors.New("invalid date range")
)
View Source
var ErrInvalidQueryParams = errors.New("invalid query params")

Functions

func LoggingErrorEncoder

func LoggingErrorEncoder(logger *slog.Logger, enc kithttp.ErrorEncoder) kithttp.ErrorEncoder

LoggingErrorEncoder is a go-kit error encoder logging decorator.

func LoggingMiddleware

func LoggingMiddleware(svc callhome.Service, logger *slog.Logger) callhome.Service

LoggingMiddleware is a middleware that adds logging facilities to the core homing service.

func MakeHandler

func MakeHandler(svc callhome.Service, tp trace.TracerProvider, logger *slog.Logger) http.Handler

MakeHandler returns a HTTP handler for API endpoints.

func MetricsMiddleware

func MetricsMiddleware(svc callhome.Service, counter metrics.Counter, latency metrics.Histogram) callhome.Service

MetricsMiddleware instruments core service by tracking request count and latency.

func ReadStringQuery

func ReadStringQuery(r *http.Request, key string, def string) (string, error)

ReadStringQuery reads the value of string http query parameters for a given key

func ReadUintQuery

func ReadUintQuery(r *http.Request, key string, def uint64) (uint64, error)

ReadUintQuery reads the value of uint64 http query parameters for a given key

Types

type ErrorRes

type ErrorRes struct {
	Err string `json:"error"`
}

ErrorRes represents the HTTP error response body.

Jump to

Keyboard shortcuts

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