api

package
v0.0.0-...-72fea12 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoAcceptedResponse

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

func DoBadRequestResponse

func DoBadRequestResponse(ctx context.Context, errors []string, fieldErrors []FieldError, writer http.ResponseWriter)

func DoErrorResponse

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

func NewEventReceiverEndpoint

func NewEventReceiverEndpoint(er EventReceiver) http.Handler

func NewRestAPI

func NewRestAPI(logger zerolog.Logger, correlationIDGenerator correlation.IDGenerator, eventEndpoint http.Handler) http.Handler

func RequestLoggingMiddleware

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

RequestLoggingMiddleware logs request/response details. Note, this relies upon a logger being in the context and should be added after a ZerologLogAttachMiddleware

func WrapWithSegment

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

func ZerologLogAttachMiddleware

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

ZerologLogAttachMiddleware attaches the provided logger to all request contexts

Types

type AcceptedResponse

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

type BadRequestResponse

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

type ErrorResponse

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

type EventReceiver

type EventReceiver interface {
	ReceiveInboundEvent(ctx context.Context, source, message string) error
}

type FieldError

type FieldError struct {
	Field         string `json:"field"`
	Error         string `json:"error"`
	CorrelationID string `json:"correlationId"`
}

type InboundEventPayload

type InboundEventPayload struct {
	Message string `json:"message"`
	Source  string `json:"source"`
}

Jump to

Keyboard shortcuts

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