defaults

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SQLite3 = "sqlite3"
	MySQL   = "mysql"
)

Supported database drivers.

View Source
const (
	// Middleware wrapper IDs.
	CORSID       = "cors"
	ReqHandlerID = "reqhandler"

	// HTTP headers.
	XSpanID = "X-Span-ID"
)

Variables

This section is empty.

Functions

func CORSWrapper

func CORSWrapper(opts *middleware.CORSOptions) endpoint.Wrapper

CORSWrapper creates a new Wrapper for the CORS endpoint.

Parameters:

  • opts: The CORS options.

Returns:

  • endpoint.Wrapper: The CORS wrapper.

func ConnectConfig

func ConnectConfig() (*database.ConnectConfig, error)

ConnectConfig returns a connection config based on environment variables. It wil determine the database driver based on an environment variable. If a configuration is provided it is used, otherwise a configuration is built from environment variables.

Parameters:

  • cfg: An optional connection configuration to use.

Returns:

  • *database.ConnectConfig: The connection configuration.
  • error: An error if the connection fails.

func CtxLogger

func CtxLogger(ctx context.Context) logging.ILogger

CtxLogger returns a logger for the given context using the current factory.

Parameters:

  • ctx: The context to use.

Returns:

  • ILogger: The logger.

func EmitterLogger

func EmitterLogger(
	eventEmitter ...event.EventEmitter,
) event.EmitterLogger

EmitterLogger returns an emitter logger using the current factory.

Parameters:

  • eventEmitter: The event emitter.

Returns:

  • EmitterLogger: The emitter logger.

func GenerateSpanID

func GenerateSpanID() string

GenerateSpanID generates a new span ID.

Returns:

  • string: The new span ID.

func GetConnection

func GetConnection(cfg ...*database.ConnectConfig) (database.DB, error)

GetConnection returns a database connection. If a configuration is provided it is used, otherwise a configuration is built from environment variables.

Parameters:

  • cfg: An optional connection configuration to use.

Returns:

  • DB: A database connection.
  • error: An error if the connection fails.

func GetDBDriverName

func GetDBDriverName(cfg ...*database.ConnectConfig) string

GetDBDriverName returns the name of the database driver. If a configuration is provided it is used, otherwise a configuration is built from environment variables.

Parameters:

  • cfg: An optional connection configuration to use.

Returns:

  • string: The name of the database driver.

func GetMySQLConnection

func GetMySQLConnection(cfg ...*database.ConnectConfig) (database.DB, error)

GetMySQLConnection establishes a MySQL database connection. If a configuration is provided it is used, otherwise a configuration is built from environment variables.

Parameters:

  • cfg: An optional connection configuration to use.

Returns:

  • DB: A database connection.
  • error: An error if the connection fails.

func GetSQLiteConnection

func GetSQLiteConnection(cfg ...*database.ConnectConfig) (database.DB, error)

GetSQLiteConnection establishes a SQLite database connection. If a configuration is provided it is used, otherwise a configuration is built from environment variables.

Parameters:

  • cfg: An optional connection configuration to use.

Returns:

  • DB: A database connection.
  • error: An error if the connection fails.

func InputConversionRules

func InputConversionRules() map[string]func(any) any

InputConversionRules returns the default input conversion rules.

Returns:

  • map[string]func(any) any: The input conversion rules.

func LoggerPlain

func LoggerPlain(
	startTime time.Time, traceID string, spanID string,
) logging.ILogger

LoggerPlain returns a logger with plain formatting using the current factory.

Parameters:

  • startTime: The start time.
  • traceID: The trace ID.
  • spanID: The span ID.

Returns:

  • ILogger: The logger.

func MustStartServer

func MustStartServer(endpoints []endpoint.Endpoint)

StartServer starts the server. It panics if an error occurs.

Parameters:

  • endpoints: The endpoints to serve.

func MutatorRepo

func MutatorRepo[
	Entity database.Mutator,
]() db.MutatorRepository[Entity]

MutatorRepo returns a new MutatorRepo.

Returns:

  • MutatorRepo: A new MutatorRepo.

func Query

func Query() db.Query

Query returns a new Query.

Returns:

  • Query: A new Query.

func QueryErrorChecker

func QueryErrorChecker() database.ErrorChecker

QueryErrorChecker returns a new QueryErrorChecker.

Returns:

  • QueryErrorChecker: A new QueryErrorChecker.

func RawQueryer

func RawQueryer() db.RawQueryer

RawQueryer returns a new RawQueryer.

Returns:

  • RawQueryer: A new RawQueryer.

func ReaderRepo

func ReaderRepo[
	Entity database.Getter,
]() db.ReaderRepository[Entity]

ReaderRepo returns a new ReaderRepo.

Returns:

  • ReaderRepo: A new ReaderRepo.

func RegisterDriver

func RegisterDriver(name string, provider DriverProvider)

RegisterDriver registers a database driver provider by name.

func RegisterErrorCheckerFactory

func RegisterErrorCheckerFactory(
	driver string,
	f func() database.ErrorChecker,
)

RegisterErrorCheckerFactory registers an error checker factory for a specific driver.

func RegisterQueryFactory

func RegisterQueryFactory(driver string, f func() db.Query)

RegisterQueryFactory registers a query factory for a specific driver.

func ReqHandlerWrapper

func ReqHandlerWrapper(
	traceIDFn func(r *http.Request) string,
	spanIDFn func(r *http.Request) string,
	loggerFactoryFn logging.CtxLoggerFactoryFn,
) endpoint.Wrapper

ReqHandlerWrapper creates a new Wrapper for the reqhandler endpoint.

Parameters:

  • traceIDFn: The trace ID function.
  • spanIDFn: The span ID function.
  • loggerFactoryFn: The logger factory function.

Returns:

  • endpoint.Wrapper: The reqhandler wrapper.

func ResetEmitterLoggerFactory

func ResetEmitterLoggerFactory()

ResetEmitterLoggerFactory resets the EmitterLogger factory to its default.

func ResetLoggerFactory

func ResetLoggerFactory()

ResetLoggerFactory resets the logger factory to its default.

func ResetLoggerPlainFactory

func ResetLoggerPlainFactory()

ResetLoggerPlainFactory resets the LoggerPlain factory to its default.

func SetDatabaseEnvConfig

func SetDatabaseEnvConfig(cfg DatabaseEnvConfig)

SetDatabaseEnvConfig allows clients to override the default database env var names.

func SetEmitterLoggerFactory

func SetEmitterLoggerFactory(
	factory func([]event.EventEmitter) event.EmitterLogger,
)

SetEmitterLoggerFactory allows clients to override the default EmitterLogger.

Parameters:

  • factory: The EmitterLogger factory.

func SetEnvVarConfig

func SetEnvVarConfig(cfg EnvVarConfig)

SetEnvVarConfig allows overriding the default environment variable names.

Parameters:

  • cfg EnvVarConfig: The environment variable names.

func SetLoggerFactory

func SetLoggerFactory(
	factory func(ctx context.Context) logging.ILogger,
)

SetLoggerFactory allows clients to override the default logger factory.

Parameters:

  • factory: The logger factory.

func SetLoggerPlainFactory

func SetLoggerPlainFactory(factory func(
	startTime time.Time, traceID string, spanID string,
) logging.ILogger,
)

SetLoggerPlainFactory allows clients to override the default LoggerPlain.

Parameters:

  • factory: The LoggerPlain factory.

func SetServerEnvConfig

func SetServerEnvConfig(cfg ServerEnvConfig)

SetServerEnvConfig allows clients to override the default server env var names.

Parameters:

  • cfg: The server environment variable names.

func SetStackEnvConfig

func SetStackEnvConfig(cfg StackEnvConfig)

SetStackEnvConfig allows clients to override the default stack env var names.

Parameters:

  • cfg: The stack environment variable names.

func SetUUIDGenFactory

func SetUUIDGenFactory(factory func() *UUIDGen)

SetUUIDGenFactory allows overriding the default UUID generator.

Parameters:

  • factory: The UUID generator factory.

func StartServer

func StartServer(endpoints []endpoint.Endpoint) error

StartServer starts the server.

Parameters:

  • endpoints: The endpoints to serve.

Returns:

  • error: An error if the server fails to start.

func TxManager

func TxManager[T any]() db.TxManager[T]

TxManager returns a new TxManager.

Returns:

  • TxManager: A new TxManager.

func ValidationRules

func ValidationRules() map[string]func(any) error

ValidationRules returns the default validation rules.

Returns:

  • map[string]func(any) error: The validation rules.

func WrapCtxLoggerFactory

func WrapCtxLoggerFactory(
	factoryFn logging.CtxLoggerFactoryFn,
) logging.LoggerFactoryFn

WrapCtxLoggerFactory wraps a context-based logger factory into a LoggerFactoryFn.

Parameters:

  • factoryFn: The context-based logger factory.

Returns:

  • LoggerFactoryFn: The wrapped logger factory.

Types

type DatabaseEnvConfig

type DatabaseEnvConfig struct {
	DatabaseDriver  string
	SQLiteName      string
	MySQLName       string
	MySQLDatabase   string
	MySQLUser       string
	MySQLPassword   string
	MySQLUseUnix    string
	MySQLHost       string
	MySQLPort       string
	MySQLSocketDir  string
	MySQLSocketName string
}

DatabaseEnvConfig holds the names of environment variables for database connections.

func GetDatabaseEnvConfig

func GetDatabaseEnvConfig() DatabaseEnvConfig

GetDatabaseEnvConfig returns the current database env var configuration.

type DriverProvider

type DriverProvider struct {
	NewConfigFromEnv func(DatabaseEnvConfig) *database.ConnectConfig
	DSN              func(database.ConnectConfig) (string, error)
}

DriverProvider defines how a driver integrates with the framework.

It provides a way to construct a ConnectConfig from env vars and to produce a DSN string for the given configuration.

type EnvVarConfig

type EnvVarConfig struct {
	LoggingCompact   string
	LoggingAnsiCodes string
	LoggingLevel     string
}

EnvVarConfig holds the names of the environment variables used.

func GetEnvVarConfig

func GetEnvVarConfig() EnvVarConfig

GetEnvVarConfig returns the current environment variable configuration.

Returns:

  • EnvVarConfig: The environment variable configuration.

type LoggingConfig

type LoggingConfig struct {
	LoggingLevel logging.LogLevel
	Compact      bool
	AnsiCodes    bool
}

LoggingConfig holds the logging configuration.

func NewLoggingConfig

func NewLoggingConfig() *LoggingConfig

NewLoggingConfig returns a new LoggingConfig. It reads the environment variables for logging configuration.

Returns:

  • *LoggingConfig: The logging configuration.

type MySQLConfig

type MySQLConfig struct {
	Database      string
	User          string
	Password      string
	UseUnixSocket bool
	Host          string
	Port          int
	SocketDir     string
	SocketName    string
}

MySQLConfig holds the configuration for a MySQL connection.

func (MySQLConfig) ConnectConfig

func (cfg MySQLConfig) ConnectConfig() *database.ConnectConfig

ConnectConfig returns a connection config configured for MySQL.

Returns:

  • *database.ConnectConfig: The connection configuration.

type SQLiteConfig

type SQLiteConfig struct {
	DatabaseName string
}

SQLiteConfig holds the configuration for a SQLite connection.

func (SQLiteConfig) ConnectConfig

func (cfg SQLiteConfig) ConnectConfig() *database.ConnectConfig

ConnectConfig returns a connection config configured for SQLite.

Returns:

  • *database.ConnectConfig: The connection configuration.

type ServerConfig

type ServerConfig struct {
	Port int
}

ServerConfig holds the server configuration.

func NewServerConfig

func NewServerConfig() *ServerConfig

NewServerConfig returns a new instance of the server config.

Returns:

  • *ServerConfig: The server config.

type ServerEnvConfig

type ServerEnvConfig struct {
	ServerPort string
}

ServerEnvConfig holds the names of the environment variables used.

func GetServerEnvConfig

func GetServerEnvConfig() ServerEnvConfig

GetServerEnvConfig returns the current server env var configuration.

Returns:

  • ServerEnvConfig: The server environment variable configuration.

type StackBuilder

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

StackBuilder builds a middleware stack.

func NewStackBuilder

func NewStackBuilder() *StackBuilder

NewStackBuilder returns a default stack builder.

Returns:

  • *StackBuilder: The stack builder.

func (*StackBuilder) Build

func (b *StackBuilder) Build() endpoint.Stack

Build returns a new stack from the builder.

Returns:

  • endpoint.Stack: The new stack.

func (*StackBuilder) Clone

func (b *StackBuilder) Clone() *StackBuilder

Clone returns a copy of the stack builder.

Returns:

  • *StackBuilder: The cloned stack builder.

type StackConfig

type StackConfig struct {
	AlwaysNewSpan bool
}

StackConfig returns the stack configuration.

func NewStackConfig

func NewStackConfig() *StackConfig

NewStackConfig returns a default stack config.

Returns:

  • *StackConfig: The stack config.

type StackEnvConfig

type StackEnvConfig struct {
	AlwaysNewSpanID string
}

StackEnvConfig holds the names of the environment variables used.

func GetStackEnvConfig

func GetStackEnvConfig() StackEnvConfig

GetStackEnvConfig returns the current stack env var configuration.

Returns:

  • StackEnvConfig: The stack environment variable configuration.

type UUID

type UUID string

UUID is a string alias that represents a UUID.

func (UUID) String

func (u UUID) String() string

String returns the string representation of the UUID.

Returns:

  • string: The string representation of the UUID.

type UUIDGen

type UUIDGen struct{}

UUIDGen implements the default UUID generation.

func NewUUIDGen

func NewUUIDGen() *UUIDGen

NewUUIDGen returns a new UUID generator using the current factory.

Returns:

  • *UUIDGen: A new UUID generator.

func (*UUIDGen) FromString

func (g *UUIDGen) FromString(s string) (UUID, error)

FromString creates a UUID from the given string.

Returns:

  • UUID: A UUID conforming to Version 4 and Variant 1.
  • error: An error if the input string is invalid.

func (*UUIDGen) IsValid

func (g *UUIDGen) IsValid(s string) bool

IsValid returns true if the given string is a valid UUID.

Parameters:

  • s: The string to validate.

Returns:

  • bool: True if the string is a valid UUID, false otherwise.

func (*UUIDGen) MustFromString

func (g *UUIDGen) MustFromString(s string) UUID

MustFromString creates a UUID from the given string, panicking on error.

Parameters:

  • s: The string to convert to a UUID.

Returns:

  • UUID: A UUID conforming to Version 4 and Variant 1.

func (*UUIDGen) MustRandom

func (g *UUIDGen) MustRandom() UUID

MustRandom returns a random UUID and panics on error.

Returns:

  • UUID: A random UUID conforming to Version 4 and Variant 1.

func (*UUIDGen) Random

func (g *UUIDGen) Random() (UUID, error)

Random returns a random UUID or an error.

Returns:

  • UUID: A random UUID conforming to Version 4 and Variant 1.
  • error: An error if crypto/rand fails.

func (*UUIDGen) Zero

func (g *UUIDGen) Zero() UUID

Zero returns a pointer to a zero-value UUID.

Returns:

  • *UUID: A pointer to a zero-value UUID.

Jump to

Keyboard shortcuts

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