contracts

package
v4.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package contracts contains adapter-facing infrastructure contracts owned by the contrib module rather than the stable root API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CORSHandler

type CORSHandler interface {
	Handler(opts CORSOptions) func(http.Handler) http.Handler
}

CORSHandler defines the contrib CORS handler shape.

type CORSOptions

type CORSOptions struct {
	AllowedOrigins   []string
	AllowedMethods   []string
	AllowedHeaders   []string
	AllowCredentials bool
	MaxAge           int
}

CORSOptions defines contrib CORS configuration.

type DatabaseConnection

type DatabaseConnection interface {
	Query(ctx context.Context, sql string, args ...any) (DatabaseRows, error)
	QueryRow(ctx context.Context, sql string, args ...any) DatabaseRow
	Exec(ctx context.Context, sql string, args ...any) (DatabaseResult, error)
	Begin(ctx context.Context) (DatabaseTransaction, error)
	Release()
}

DatabaseConnection defines an adapter-level database connection.

type DatabasePool

type DatabasePool interface {
	Ping(ctx context.Context) error
	Close()
	Acquire(ctx context.Context) (DatabaseConnection, error)
}

DatabasePool defines the database capability shared by contrib adapters.

type DatabasePoolSnapshot

type DatabasePoolSnapshot struct {
	AcquireCount         int64
	AcquireDuration      time.Duration
	AcquiredConns        int32
	CanceledAcquireCount int64
	ConstructingConns    int32
	EmptyAcquireCount    int64
	IdleConns            int32
	MaxConns             int32
	NewConnsCount        int64
	TotalConns           int32
}

DatabasePoolSnapshot captures plain-value connection-pool statistics.

func SnapshotDatabasePoolStats

func SnapshotDatabasePoolStats(pool DatabasePool) DatabasePoolSnapshot

SnapshotDatabasePoolStats copies an optional pool snapshot.

type DatabasePoolSnapshotProvider

type DatabasePoolSnapshotProvider interface {
	StatSnapshot() DatabasePoolSnapshot
}

DatabasePoolSnapshotProvider exposes an optional plain-value pool snapshot.

type DatabaseResult

type DatabaseResult interface {
	RowsAffected() int64
}

DatabaseResult defines an adapter-level execution result.

type DatabaseRow

type DatabaseRow interface {
	Scan(dest ...any) error
}

DatabaseRow defines an adapter-level single row result.

type DatabaseRows

type DatabaseRows interface {
	Next() bool
	Scan(dest ...any) error
	Close()
	Err() error
}

DatabaseRows defines an adapter-level query result collection.

type DatabaseTransaction

type DatabaseTransaction interface {
	Query(ctx context.Context, sql string, args ...any) (DatabaseRows, error)
	QueryRow(ctx context.Context, sql string, args ...any) DatabaseRow
	Exec(ctx context.Context, sql string, args ...any) (DatabaseResult, error)
	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
}

DatabaseTransaction defines an adapter-level transaction.

type EnvVar

type EnvVar interface {
	LoadEnvFiles(paths []string) error
	Get(key string) (string, bool)
	GetOr(key, def string) string
	MustGet(key string) string
	GetBoolOr(key string, def bool) bool
	MustGetBool(key string) bool
	GetIntOr(key string, def int) int
	MustGetInt(key string) int
	GetInt64Or(key string, def int64) int64
	MustGetInt64(key string) int64
	GetUintOr(key string, def uint) uint
	MustGetUint(key string) uint
	GetUint64Or(key string, def uint64) uint64
	MustGetUint64(key string) uint64
	GetFloat64Or(key string, def float64) float64
	MustGetFloat64(key string) float64
	MustGetDuration(key string) time.Duration
	GetDurationOr(key string, def time.Duration) time.Duration
	Bind(dst any) error
	MustBind(dst any)
	BindWithPrefix(dst any, prefix string) error
	MustBindWithPrefix(dst any, prefix string)
	DumpRedacted() map[string]string
}

EnvVar manages environment variables with typed getters for contrib config.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient describes an outbound HTTP client used by contrib adapters.

type HTTPMiddleware

type HTTPMiddleware interface {
	RequestID() func(http.Handler) http.Handler
	RealIP() func(http.Handler) http.Handler
	Recoverer() func(http.Handler) http.Handler
}

HTTPMiddleware defines common router middleware capabilities.

type HTTPRouter

type HTTPRouter interface {
	http.Handler
	Get(pattern string, h http.HandlerFunc)
	Post(pattern string, h http.HandlerFunc)
	Put(pattern string, h http.HandlerFunc)
	Delete(pattern string, h http.HandlerFunc)
	Mount(pattern string, h http.Handler)
	Use(middlewares ...func(http.Handler) http.Handler)
}

HTTPRouter defines the router shape used by contrib composition.

type MethodRouteRegistrar

type MethodRouteRegistrar interface {
	Get(pattern string, h http.HandlerFunc)
}

MethodRouteRegistrar defines the GET-only route registration shape used by adapters.

type Middleware

type Middleware interface {
	Middleware() func(http.Handler) http.Handler
}

Middleware defines the adapter middleware shape.

type MiddlewareChain

type MiddlewareChain interface {
	Use(middlewares ...func(http.Handler) http.Handler)
}

MiddlewareChain defines the middleware registration shape used by adapters.

type Migrator

type Migrator interface {
	Up(ctx context.Context, dir string) error
	Down(ctx context.Context, dir string) error
	Status(ctx context.Context, dir string) (string, error)
	Close() error
}

Migrator defines the adapter migration lifecycle contract.

type TxManager

type TxManager interface {
	WithinTx(ctx context.Context, fn func(ctx context.Context) error) error
}

TxManager runs a function within an adapter-owned transaction boundary.

type URLParamExtractor

type URLParamExtractor interface {
	URLParam(r *http.Request, key string) string
}

URLParamExtractor defines the router path-parameter capability used by adapters.

type Validator

type Validator interface {
	Validate(ctx context.Context, value interface{}) error
	ValidateStruct(ctx context.Context, obj interface{}) error
	ValidateField(ctx context.Context, obj interface{}, field string) error
}

Validator defines the adapter validation contract.

Jump to

Keyboard shortcuts

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