core

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete[In any, Out any](router Router, path string, handler Handler[In, Out], opts ...OperationOption)

Delete registers a typed DELETE operation.

func Get

func Get[In any, Out any](router Router, path string, handler Handler[In, Out], opts ...OperationOption)

Get registers a typed GET operation.

func Head[In any, Out any](router Router, path string, handler Handler[In, Out], opts ...OperationOption)

Head registers a typed HEAD operation.

func NewHTTPError

func NewHTTPError(status int, detail string) error

NewHTTPError creates an error that handlers can return to control HTTP status.

func Options

func Options[In any, Out any](router Router, path string, handler Handler[In, Out], opts ...OperationOption)

Options registers a typed OPTIONS operation.

func Patch

func Patch[In any, Out any](router Router, path string, handler Handler[In, Out], opts ...OperationOption)

Patch registers a typed PATCH operation.

func Post

func Post[In any, Out any](router Router, path string, handler Handler[In, Out], opts ...OperationOption)

Post registers a typed POST operation.

func Put

func Put[In any, Out any](router Router, path string, handler Handler[In, Out], opts ...OperationOption)

Put registers a typed PUT operation.

Types

type App

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

App is a net/http-compatible application.

func New

func New(config Config) *App

New creates an application with OpenAPI and docs endpoints registered.

func (*App) Group

func (app *App) Group(prefix string, opts ...OperationOption) *Group

Group creates a route group below the app.

func (*App) Provide

func (app *App) Provide(dependencies ...DependencyResolver)

Provide registers app-level dependencies.

func (*App) RegisterSecurity

func (app *App) RegisterSecurity(schemes ...SecurityScheme)

RegisterSecurity adds OpenAPI security schemes to the app.

func (*App) ServeHTTP

func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

func (*App) Use

func (app *App) Use(middlewares ...Middleware)

Use appends middleware to routes registered after this call.

type Attachment

type Attachment struct {
	Status      int
	Headers     http.Header
	Path        string
	Filename    string
	ContentType string
}

Attachment streams a file with Content-Disposition: attachment.

type Config

type Config struct {
	Title   string
	Version string
}

Config describes the generated API document and built-in docs endpoints.

type Dependency

type Dependency[T any] struct {
	Name     string
	Resolver func(context.Context, *http.Request) (T, error)
}

Dependency resolves a request-scoped value that can be injected into input structs.

func APIKeyHeaderDep

func APIKeyHeaderDep(name, header string) Dependency[string]

APIKeyHeaderDep injects an API key from a header into a dep-tagged field.

func APIKeyQueryDep

func APIKeyQueryDep(name, query string) Dependency[string]

APIKeyQueryDep injects an API key from a query parameter into a dep-tagged field.

func BearerTokenDep

func BearerTokenDep(name string) Dependency[string]

BearerTokenDep injects the Authorization bearer token into a dep-tagged field.

func Dep

func Dep[T any](name string, resolver func(context.Context, *http.Request) (T, error)) Dependency[T]

Dep creates a named request dependency.

type DependencyResolver

type DependencyResolver interface {
	// contains filtered or unexported methods
}

type FieldError

type FieldError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
	Code    string `json:"code"`
}

FieldError describes a field-level binding or validation error.

type File

type File struct {
	Status      int
	Headers     http.Header
	Path        string
	ContentType string
}

File streams a file from disk.

type Group

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

Group registers routes under a shared path prefix and middleware stack.

func (*Group) Group

func (group *Group) Group(prefix string, opts ...OperationOption) *Group

Group creates a nested route group.

func (*Group) Use

func (group *Group) Use(middlewares ...Middleware)

Use appends middleware to routes registered on the group after this call.

type HTML

type HTML struct {
	Status  int
	Headers http.Header
	Body    string
}

HTML returns an HTML response.

type HTTPError

type HTTPError struct {
	Status int
	Detail string
	Type   string
}

HTTPError maps an application error to a Problem Details response.

func (HTTPError) Error

func (err HTTPError) Error() string

type Handler

type Handler[In any, Out any] func(context.Context, In) (Out, error)

Handler is the primary typed handler shape.

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is standard Go HTTP middleware.

type NoContent

type NoContent struct {
	Headers http.Header
}

NoContent returns a response with no body.

type Operation

type Operation struct {
	OperationID string
	Summary     string
	Description string
	Tags        []string
	Status      int
	// contains filtered or unexported fields
}

Operation stores metadata used by routing and OpenAPI generation.

type OperationOption

type OperationOption func(*Operation)

OperationOption configures route metadata.

func Description

func Description(description string) OperationOption

Description sets the OpenAPI description.

func OperationID

func OperationID(id string) OperationOption

OperationID sets the OpenAPI operationId.

func Require

func Require(dependencies ...DependencyResolver) OperationOption

Require registers route-level dependencies.

func Security

func Security(names ...string) OperationOption

Security adds an OpenAPI security requirement by scheme name.

func Status

func Status(status int) OperationOption

Status sets the success status code.

func Summary

func Summary(summary string) OperationOption

Summary sets the OpenAPI summary.

func Tags

func Tags(tags ...string) OperationOption

Tags sets OpenAPI tags.

func Use

func Use(middlewares ...Middleware) OperationOption

Use adds middleware to a route or group.

type Problem

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

Problem is an RFC 9457 Problem Details response.

type Redirect

type Redirect struct {
	Status   int
	Headers  http.Header
	Location string
}

Redirect returns a redirect response.

type Response

type Response[T any] struct {
	Status  int
	Headers http.Header
	Body    T
}

Response gives handlers control over status, headers, and body.

type Router

type Router interface {
	// contains filtered or unexported methods
}

Router is implemented by App and Group route targets.

type SSE

type SSE struct {
	Status  int
	Headers http.Header
	Events  []SSEEvent
}

SSE writes server-sent events.

type SSEEvent

type SSEEvent struct {
	Event string
	ID    string
	Retry int
	Data  string
}

SSEEvent is a single server-sent event.

type SecurityScheme

type SecurityScheme struct {
	Name   string
	Type   string
	Scheme string
	In     string
}

SecurityScheme describes an OpenAPI security scheme.

func APIKeyCookie

func APIKeyCookie(name, cookie string) SecurityScheme

APIKeyCookie defines an API key security scheme read from a cookie.

func APIKeyHeader

func APIKeyHeader(name, header string) SecurityScheme

APIKeyHeader defines an API key security scheme read from a header.

func APIKeyQuery

func APIKeyQuery(name, query string) SecurityScheme

APIKeyQuery defines an API key security scheme read from a query parameter.

func BasicAuth

func BasicAuth(name string) SecurityScheme

BasicAuth defines an HTTP basic security scheme.

func BearerAuth

func BearerAuth(name string) SecurityScheme

BearerAuth defines an HTTP bearer security scheme.

type Stream

type Stream struct {
	Status      int
	Headers     http.Header
	ContentType string
	Body        io.ReadCloser
}

Stream writes an arbitrary response stream.

type Text

type Text struct {
	Status  int
	Headers http.Header
	Body    string
}

Text returns a plain-text response.

type Validator

type Validator interface {
	ValidateGapi() []FieldError
}

Validator can be implemented by input or nested model types for custom validation.

Jump to

Keyboard shortcuts

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