api

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StartTimeQueryParam       = "startTime"
	EndTimeQueryParam         = "endTime"
	PageQueryParam            = "page"
	ResultsPerPageParam       = "resultsPerPage"
	DefaultResultsPerPage int = 10

	// Analytics query params
	GroupByQueryParam     = "groupBy"
	GranularityQueryParam = "granularity"
	SeriesIDQueryParam    = "seriesId"
	CarIDQueryParam       = "carId"
	TrackIDQueryParam     = "trackId"
)

begin url parameters

View Source
const DriverIDPathParam = "driver_id"

begin path parameters

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(validator TokenValidator) func(next http.Handler) http.Handler

func DoAcceptedResponse

func DoAcceptedResponse(ctx context.Context, Response interface{}, writer http.ResponseWriter)

func DoBadRequestResponse

func DoBadRequestResponse(ctx context.Context, result RequestErrors, writer http.ResponseWriter)

func DoErrorResponse

func DoErrorResponse(ctx context.Context, writer http.ResponseWriter)

func DoForbiddenResponse

func DoForbiddenResponse(ctx context.Context, message string, writer http.ResponseWriter)

func DoNotFoundResponse

func DoNotFoundResponse(ctx context.Context, message string, writer http.ResponseWriter)

func DoOKListResponse

func DoOKListResponse[T any](ctx context.Context, items []T, page, resultsPerPage, totalResults int, writer http.ResponseWriter)

func DoOKResponse

func DoOKResponse(ctx context.Context, Response interface{}, writer http.ResponseWriter)

func DoTooManyRequestsResponse

func DoTooManyRequestsResponse(ctx context.Context, message string, retryAfterSeconds int, writer http.ResponseWriter)

func DoUnauthorizedResponse

func DoUnauthorizedResponse(ctx context.Context, message string, writer http.ResponseWriter)

func DriverOwnershipMiddleware

func DriverOwnershipMiddleware(pathParam string) func(next http.Handler) http.Handler

func EntitlementMiddleware

func EntitlementMiddleware(requiredEntitlement string) func(next http.Handler) http.Handler

func NewRestAPI

func NewRestAPI(logger zerolog.Logger, correlationIDGenerator correlation.IDGenerator, routers RootRouters, cfg RestAPIConfig) http.Handler

func ReduceDeadlineMiddleware

func ReduceDeadlineMiddleware(buffer time.Duration) func(next http.Handler) http.Handler

ReduceDeadlineMiddleware reduces existing context deadlines by the specified buffer. If no deadline exists, the context is passed through unchanged.

func RequestLoggingMiddleware

func RequestLoggingMiddleware() func(next http.Handler) http.Handler

func SensitiveClaimsFromContext

func SensitiveClaimsFromContext(ctx context.Context) *auth.SensitiveClaims

func SessionClaimsFromContext

func SessionClaimsFromContext(ctx context.Context) *auth.SessionClaims

func WrapWithSegment

func WrapWithSegment(segmentName string, handler http.Handler) http.Handler

func ZerologLogAttachMiddleware

func ZerologLogAttachMiddleware(logger zerolog.Logger) func(next http.Handler) http.Handler

Types

type AcceptedResponse

type AcceptedResponse struct {
	Response      interface{} `json:"response"`
	CorrelationID string      `json:"correlationId"`
}

type ErrorResponse

type ErrorResponse struct {
	Message       string `json:"message"`
	CorrelationID string `json:"correlationId"`
}

type FieldError

type FieldError struct {
	Field  string            `json:"field"`
	Error  string            `json:"error,omitempty"`
	Code   string            `json:"code,omitempty"`
	Params map[string]string `json:"params,omitempty"`
}

type ForbiddenResponse

type ForbiddenResponse struct {
	Message       string `json:"message"`
	CorrelationID string `json:"correlationId"`
}

type NotFoundResponse

type NotFoundResponse struct {
	Message       string `json:"message"`
	CorrelationID string `json:"correlationId"`
}

type OKListResponse

type OKListResponse[T any] struct {
	Items         []T        `json:"items"`
	Pagination    Pagination `json:"pagination"`
	CorrelationID string     `json:"correlationId"`
}

type OKResponse

type OKResponse struct {
	Response      interface{} `json:"response"`
	CorrelationID string      `json:"correlationId"`
}

type Pagination

type Pagination struct {
	Page           int `json:"page"`
	ResultsPerPage int `json:"resultsPerPage"`
	TotalResults   int `json:"totalResults"`
	TotalPages     int `json:"totalPages"`
}

type RequestErrors

type RequestErrors struct {
	Errors        []string     `json:"errors"`
	FieldErrors   []FieldError `json:"fieldErrors"`
	CorrelationID string       `json:"correlationId"`
}

func NewRequestErrors

func NewRequestErrors() RequestErrors

func (RequestErrors) HasAnyError

func (r RequestErrors) HasAnyError() bool

func (RequestErrors) WithError

func (r RequestErrors) WithError(error string) RequestErrors

func (RequestErrors) WithFieldError

func (r RequestErrors) WithFieldError(field, error string) RequestErrors

func (RequestErrors) WithFieldErrorCode

func (r RequestErrors) WithFieldErrorCode(field, code string, params map[string]string) RequestErrors

type RestAPIConfig

type RestAPIConfig struct {
	CORSAllowedOrigins []string
	// DeadlineBuffer is subtracted from existing context deadlines to leave room for cleanup.
	DeadlineBuffer time.Duration
}

type RootRouters

type RootRouters struct {
	HealthRouter    http.Handler
	AuthRouter      http.Handler
	DeveloperRouter http.Handler
	IngestionRouter http.Handler
	DriverRouter    http.Handler
	TracksRouter    http.Handler
	CarsRouter      http.Handler
	SeriesRouter    http.Handler
	SessionRouter   http.Handler
}

type TokenValidator

type TokenValidator interface {
	ValidateToken(ctx context.Context, tokenString string) (*auth.SessionClaims, *auth.SensitiveClaims, error)
}

type TooManyRequestsResponse

type TooManyRequestsResponse struct {
	Message       string `json:"message"`
	RetryAfter    int    `json:"retryAfter"`
	CorrelationID string `json:"correlationId"`
}

type UnauthorizedResponse

type UnauthorizedResponse struct {
	Message       string `json:"message"`
	CorrelationID string `json:"correlationId"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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