core

package
v0.0.0-...-f76794d Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CorrelationIDHeader                = "Correlation-Id"
	CorrelationIDContextKey contextKey = "correlation_id"
)

Variables

This section is empty.

Functions

func CorrelationIDHTTPMiddleware

func CorrelationIDHTTPMiddleware(next http.HandlerFunc) http.HandlerFunc

func LogError

func LogError(ctx context.Context, message string, fields ...any)

func Map

func Map[TSource any, TResult any](source []TSource, m func(TSource) TResult) []TResult

func RequestBody

func RequestBody[TRequest any](r *http.Request) (TRequest, error)

func Tx

func Tx(
	ctx context.Context,
	db *sql.DB,
	transaction func(context.Context, *sql.Tx) error,
	opts ...TransactionOption,
) (err error)

func WriteBadGateway

func WriteBadGateway(w http.ResponseWriter, r *http.Request, body any)

func WriteBadRequest

func WriteBadRequest(w http.ResponseWriter, r *http.Request, body any)

func WriteCommandError

func WriteCommandError(w http.ResponseWriter, r *http.Request, err error, opts ...ResponseOption)

func WriteCreated

func WriteCreated(w http.ResponseWriter, r *http.Request, location string, opts ...ResponseOption)

func WriteInternalServerError

func WriteInternalServerError(w http.ResponseWriter, r *http.Request, body any)

func WriteOK

func WriteOK(w http.ResponseWriter, r *http.Request, body any)

func WriteResponse

func WriteResponse(
	w http.ResponseWriter,
	r *http.Request,
	statusCode int,
	body any,
	opts ...ResponseOption,
)

func WriteUnauthorized

func WriteUnauthorized(w http.ResponseWriter, r *http.Request, body any)

Types

type CommandError

type CommandError struct {
	Payload    any
	StatusCode int
	Reason     *string
}

func NewCommandError

func NewCommandError(statusCode int, payload any, opts ...CommandErrorOption) CommandError

func (CommandError) Error

func (r CommandError) Error() string

type CommandErrorOption

type CommandErrorOption func(*CommandError)

func WithReason

func WithReason(reason string) CommandErrorOption

type ContextKey

type ContextKey string
const SessionContextKey ContextKey = "session"

type ContextSession

type ContextSession struct {
	UserID uuid.UUID
}

func Session

func Session(ctx context.Context) ContextSession

type EmailClient

type EmailClient struct {
	// contains filtered or unexported fields
}

func NewEmailClient

func NewEmailClient(
	host *url.URL,
	auth smtp.Auth,
) *EmailClient

TODO: pass in smtp.Auth directly instead of username/password.

func (*EmailClient) Send

func (c *EmailClient) Send(m MailMessage) error

type HandlerErrorLoggingBehavior

type HandlerErrorLoggingBehavior struct {
	Logger *slog.Logger
}

func (*HandlerErrorLoggingBehavior) Handle

func (b *HandlerErrorLoggingBehavior) Handle(
	ctx context.Context,
	request any,
	next mediator.RequestHandlerFunc,
) (any, error)

type MailMessage

type MailMessage struct {
	Subject    string
	From       string
	To         []string
	Cc         []string
	Bcc        []string
	BodyString string
	IsHTML     bool
}

func (MailMessage) Content

func (m MailMessage) Content() []byte

type RequestLoggingBehavior

type RequestLoggingBehavior struct {
	Logger *slog.Logger
}

func (*RequestLoggingBehavior) Handle

func (b *RequestLoggingBehavior) Handle(
	ctx context.Context,
	request any,
	next mediator.RequestHandlerFunc,
) (any, error)

type RequestValidationBehavior

type RequestValidationBehavior struct{}

func (*RequestValidationBehavior) Handle

func (b *RequestValidationBehavior) Handle(
	ctx context.Context,
	request any,
	next mediator.RequestHandlerFunc,
) (any, error)

type ResponseOption

type ResponseOption func(http.ResponseWriter, *http.Request)

func WithBody

func WithBody(body any) ResponseOption

func WithHeader

func WithHeader(header, value string) ResponseOption

type TransactionOption

type TransactionOption func(*sql.TxOptions)

func WithIsolationLevel

func WithIsolationLevel(isolationLevel sql.IsolationLevel) TransactionOption

type Unit

type Unit struct{}

type ValidationError

type ValidationError struct {
	ValidationErrors []error
}

func (ValidationError) Error

func (e ValidationError) Error() string

type Validator

type Validator interface {
	Validate() error
}

Jump to

Keyboard shortcuts

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