httpkit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

func CORS(
	allowedOrigins []string,
) func(http.Handler) http.Handler

func NewResponseErrorHandler

func NewResponseErrorHandler(
	reporter ErrorReporter,
) func(
	http.ResponseWriter,
	*http.Request,
	error,
)

func OpenAPIValidation

func OpenAPIValidation(
	spec *openapi3.T,
	verifier appauth.TokenVerifier,
) func(http.Handler) http.Handler

func Recovery

func Recovery(
	logger *slog.Logger,
	next http.Handler,
) http.Handler

func RequestErrorHandler

func RequestErrorHandler(
	w http.ResponseWriter,
	r *http.Request,
	err error,
)

func WriteProblem

func WriteProblem(
	w http.ResponseWriter,
	status int,
	title string,
	detail string,
)

Types

type ErrorReporter

type ErrorReporter interface {
	CaptureException(
		ctx context.Context,
		err error,
	)
}

type Health

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

func NewHealth

func NewHealth(
	database Pinger,
) *Health

func (*Health) Live

func (h *Health) Live(
	w http.ResponseWriter,
	_ *http.Request,
)

func (*Health) Ready

func (h *Health) Ready(
	w http.ResponseWriter,
	r *http.Request,
)

type Pinger

type Pinger interface {
	Ping(context.Context) error
}

type Problem

type Problem struct {
	Type   string `json:"type"`
	Title  string `json:"title"`
	Status int    `json:"status"`
	Detail string `json:"detail,omitempty"`
}

type Responder

type Responder[R, T any] struct {
	// OK builds the success response from the service value.
	OK func(T) R

	// NotFound is the response for a service result that reports no match.
	// Leave it zero for operations whose spec declares no 404.
	NotFound R
}

Responder binds the response types of one generated operation, so handlers can feed a service result straight in and stay a single line.

R is the operation's response interface (e.g. usersapi.GetUserResponseObject) and T the value the service returns. Each operation gets its own concrete 404 type from the generator, which is why NotFound is a field rather than something a plain function could return.

func (Responder[R, T]) Exists

func (r Responder[R, T]) Exists(found bool, err error) (R, error)

Exists completes an operation whose service call only reports whether the target existed, such as a delete.

func (Responder[R, T]) Lookup

func (r Responder[R, T]) Lookup(value T, found bool, err error) (R, error)

Lookup completes an operation whose service call returns a value and reports whether it was found.

func (Responder[R, T]) Value

func (r Responder[R, T]) Value(value T, err error) (R, error)

Value completes an operation whose service call cannot report "not found".

Jump to

Keyboard shortcuts

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