Documentation
¶
Index ¶
- type CORSHandler
- type CORSOptions
- type Clock
- type DatabaseConnection
- type DatabasePool
- type DatabaseResult
- type DatabaseRow
- type DatabaseRows
- type DatabaseStats
- type DatabaseTransaction
- type DetailedHealthResponse
- type DocsConfig
- type DocsInfo
- type DocsManager
- type DocsPaths
- type DocsProvider
- type EnvVar
- type HTTPMiddleware
- type HTTPRouter
- type HealthCheckConfig
- type HealthCheckRegistry
- type HealthChecker
- type HealthManager
- type HealthResponse
- type HealthResult
- type HealthStatus
- type HealthSummary
- type IDGen
- type Logger
- type Migrator
- type SecurityHandler
- type TxManager
- type URLParamExtractor
- type Validator
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 interface for CORS handling.
type CORSOptions ¶
type CORSOptions struct {
AllowedOrigins []string
AllowedMethods []string
AllowedHeaders []string
AllowCredentials bool
MaxAge int
}
CORSOptions defines 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 the interface for individual database connections.
type DatabasePool ¶
type DatabasePool interface {
Ping(ctx context.Context) error
Close()
Acquire(ctx context.Context) (DatabaseConnection, error)
Stat() DatabaseStats
}
DatabasePool defines the interface for database connection pooling.
type DatabaseResult ¶
type DatabaseResult interface {
RowsAffected() int64
}
DatabaseResult defines the interface for query execution results.
type DatabaseRow ¶
DatabaseRow defines the interface for a single query result row.
type DatabaseRows ¶
DatabaseRows defines the interface for query result rows.
type DatabaseStats ¶
type DatabaseStats interface {
AcquireCount() int64
AcquireDuration() time.Duration
AcquiredConns() int32
CanceledAcquireCount() int64
ConstructingConns() int32
EmptyAcquireCount() int64
IdleConns() int32
MaxConns() int32
NewConnsCount() int64
TotalConns() int32
}
DatabaseStats defines the interface for database pool statistics.
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 the interface for database transactions.
type DetailedHealthResponse ¶
type DetailedHealthResponse struct {
Status HealthStatus `json:"status"`
Timestamp time.Time `json:"timestamp"`
Checks map[string]HealthResult `json:"checks"`
Summary HealthSummary `json:"summary"`
}
DetailedHealthResponse represents a detailed health response with individual checks.
type DocsConfig ¶
type DocsConfig struct {
Title string `json:"title"`
Description string `json:"description"`
Version string `json:"version"`
Contact string `json:"contact,omitempty"`
License string `json:"license,omitempty"`
Paths DocsPaths `json:"paths"`
EnableHTML bool `json:"enable_html"`
EnableJSON bool `json:"enable_json"`
EnableYAML bool `json:"enable_yaml"`
}
DocsConfig defines configuration for documentation.
type DocsInfo ¶
type DocsInfo struct {
Title string `json:"title"`
Description string `json:"description"`
Version string `json:"version"`
Contact string `json:"contact,omitempty"`
License string `json:"license,omitempty"`
}
DocsInfo provides information about the API documentation.
type DocsManager ¶
type DocsManager interface {
RegisterProvider(provider DocsProvider)
GetHTML() (string, error)
GetOpenAPI() ([]byte, error)
GetVersion() (string, error)
GetInfo() DocsInfo
ServeHTML(w http.ResponseWriter, r *http.Request)
ServeOpenAPI(w http.ResponseWriter, r *http.Request)
ServeVersion(w http.ResponseWriter, r *http.Request)
ServeInfo(w http.ResponseWriter, r *http.Request)
}
DocsManager defines the interface for managing documentation.
type DocsPaths ¶
type DocsPaths struct {
HTML string `json:"html"`
OpenAPI string `json:"openapi"`
Version string `json:"version"`
Info string `json:"info"`
}
DocsPaths defines the paths for documentation endpoints.
func DefaultDocsPaths ¶
func DefaultDocsPaths() DocsPaths
DefaultDocsPaths returns the default documentation endpoint paths.
type DocsProvider ¶
type DocsProvider interface {
GetHTML() (string, error)
GetOpenAPI() ([]byte, error)
GetVersion() (string, error)
GetInfo() DocsInfo
}
DocsProvider defines the interface for providing documentation content.
type EnvVar ¶
type EnvVar interface {
// MustGet returns the value or panics if not present.
MustGet(key string) string
// MustGetBool returns the value as a boolean or panics if not present.
MustGetBool(key string) bool
// MustGetInt returns the value as an integer or panics if not present.
MustGetInt(key string) int
// MustGetInt64 returns the value as an int64 or panics if not present.
MustGetInt64(key string) int64
// MustGetUint returns the value as a uint or panics if not present.
MustGetUint(key string) uint
// MustGetUint64 returns the value as a uint64 or panics if not present.
MustGetUint64(key string) uint64
// MustGetFloat64 returns the value as a float64 or panics if not present.
MustGetFloat64(key string) float64
// MustGetDuration returns the value as a duration or panics if not present.
MustGetDuration(key string) time.Duration
}
EnvVar manages environment variables with typed getters.
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 the interface for HTTP middleware.
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 interface for HTTP routing.
type HealthCheckConfig ¶
type HealthCheckConfig struct {
Timeout time.Duration `json:"timeout"`
CacheDuration time.Duration `json:"cache_duration"`
EnableCaching bool `json:"enable_caching"`
EnableDetailed bool `json:"enable_detailed"`
LivenessChecks []string `json:"liveness_checks"`
ReadinessChecks []string `json:"readiness_checks"`
}
HealthCheckConfig defines configuration for health checks.
type HealthCheckRegistry ¶
type HealthCheckRegistry interface {
Register(name string, checker HealthChecker)
Unregister(name string)
GetChecker(name string) (HealthChecker, bool)
ListCheckers() []string
}
HealthCheckRegistry defines the interface for registering health checks.
type HealthChecker ¶
type HealthChecker interface {
Name() string
Check(ctx context.Context) HealthResult
}
HealthChecker defines the interface for individual health checks.
type HealthManager ¶
type HealthManager interface {
RegisterChecker(checker HealthChecker)
RegisterCheckers(checkers ...HealthChecker)
GetLiveness(ctx context.Context) HealthResult
GetReadiness(ctx context.Context) HealthResult
GetHealth(ctx context.Context) HealthResponse
GetDetailedHealth(ctx context.Context) DetailedHealthResponse
}
HealthManager defines the interface for managing health checks.
type HealthResponse ¶
type HealthResponse struct {
Status HealthStatus `json:"status"`
Timestamp time.Time `json:"timestamp"`
Message string `json:"message,omitempty"`
}
HealthResponse represents the overall health response.
type HealthResult ¶
type HealthResult struct {
Status HealthStatus `json:"status"`
Message string `json:"message,omitempty"`
Details interface{} `json:"details,omitempty"`
Timestamp time.Time `json:"timestamp"`
Duration time.Duration `json:"duration,omitempty"`
}
HealthResult represents the result of a health check.
type HealthStatus ¶
type HealthStatus string
HealthStatus represents the status of a health check.
const ( HealthStatusHealthy HealthStatus = "healthy" HealthStatusUnhealthy HealthStatus = "unhealthy" HealthStatusDegraded HealthStatus = "degraded" HealthStatusUnknown HealthStatus = "unknown" )
type HealthSummary ¶
type HealthSummary struct {
Total int `json:"total"`
Healthy int `json:"healthy"`
Unhealthy int `json:"unhealthy"`
Degraded int `json:"degraded"`
Unknown int `json:"unknown"`
}
HealthSummary provides a summary of all health checks.
type Logger ¶
type Logger interface {
Debug(msg string, kv ...any)
Info(msg string, kv ...any)
Warn(msg string, kv ...any)
Error(msg string, kv ...any)
}
Logger is a tiny façade to avoid vendor lock-in.
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)
}
Migrator is the app-level contract used by main and CLI.
type SecurityHandler ¶
SecurityHandler defines the interface for security middleware.
type TxManager ¶
type TxManager interface {
WithinTx(ctx context.Context, fn func(ctx context.Context) error) error
}
TxManager runs a function within a transaction boundary.
type URLParamExtractor ¶
URLParamExtractor defines the interface for extracting URL parameters.