http

package
v0.0.0-...-f96b470 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package http provides the API server and its corresponding components.

Index

Constants

This section is empty.

Variables

View Source
var ErrDenyAllKey = fmt.Errorf("api key is not valid")

ErrDenyAllKey is defined by the default middleware denying all incoming requests.

Functions

func APIKeyMiddleware

func APIKeyMiddleware(apiKey APIKeyRepository) func(next echo.HandlerFunc) echo.HandlerFunc

APIKeyMiddleware is the middleware for validating API keys.

Types

type API

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

API is the API server.

func NewAPI

func NewAPI(handler api.ServerInterface, opts ...Opts) *API

NewAPI creates a new API server.

func (*API) Run

func (a *API) Run() error

Run runs the API server and handles graceful shutdown.

type APIKeyRepository

type APIKeyRepository interface {
	// Validate validates an API key. If the API Key is valid,
	// a user ID is returned. Otherwise an error is returned.
	Validate(ctx context.Context, key string) (uuid.UUID, error)
}

APIKeyRepository is the interface for API key repositories.

type Options

type Options struct {
	Port             int
	ShutdownDelay    time.Duration
	Logger           *slog.Logger
	Runnables        []Runnable
	WithAuthEnabled  bool
	APIKeyRepository APIKeyRepository
}

Options represents the options for the API.

type Opts

type Opts func(*Options)

Opts represents a function that modifies the options.

func WithAuthDisabled

func WithAuthDisabled() Opts

WithAuthDisabled disables authentication.

func WithAuthEnabled

func WithAuthEnabled(apiKeyRepository APIKeyRepository) Opts

WithAuthEnabled enables authentication with a given api key repository.

func WithLogger

func WithLogger(logger *slog.Logger) Opts

WithLogger sets the logger.

func WithPort

func WithPort(port int) Opts

WithPort sets the port.

func WithRunnable

func WithRunnable(runnable Runnable) Opts

WithRunnable adds a runnable.

func WithShutdownDelay

func WithShutdownDelay(delay time.Duration) Opts

WithShutdownDelay sets the shutdown delay.

type Runnable

type Runnable interface {
	Start() error
	Name() string
	Shutdown(ctx context.Context) error
}

Runnable is the interface for runnable components managed by the API.

Directories

Path Synopsis
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
Package handlers implements the handlers for the API server.
Package handlers implements the handlers for the API server.

Jump to

Keyboard shortcuts

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