Documentation
¶
Index ¶
- Constants
- func CORSWrapper(opts *middleware.CORSOptions) endpoint.Wrapper
- func ConnectConfig() (*database.ConnectConfig, error)
- func CtxLogger(ctx context.Context) logging.ILogger
- func EmitterLogger(eventEmitter ...event.EventEmitter) event.EmitterLogger
- func GenerateSpanID() string
- func GetConnection(cfg ...*database.ConnectConfig) (database.DB, error)
- func GetDBDriverName(cfg ...*database.ConnectConfig) string
- func GetMySQLConnection(cfg ...*database.ConnectConfig) (database.DB, error)
- func GetSQLiteConnection(cfg ...*database.ConnectConfig) (database.DB, error)
- func InputConversionRules() map[string]func(any) any
- func LoggerPlain(startTime time.Time, traceID string, spanID string) logging.ILogger
- func MustStartServer(endpoints []endpoint.Endpoint)
- func MutatorRepo[Entity database.Mutator]() db.MutatorRepository[Entity]
- func Query() db.Query
- func QueryErrorChecker() database.ErrorChecker
- func RawQueryer() db.RawQueryer
- func ReaderRepo[Entity database.Getter]() db.ReaderRepository[Entity]
- func RegisterDriver(name string, provider DriverProvider)
- func RegisterErrorCheckerFactory(driver string, f func() database.ErrorChecker)
- func RegisterQueryFactory(driver string, f func() db.Query)
- func ReqHandlerWrapper(traceIDFn func(r *http.Request) string, spanIDFn func(r *http.Request) string, ...) endpoint.Wrapper
- func ResetEmitterLoggerFactory()
- func ResetLoggerFactory()
- func ResetLoggerPlainFactory()
- func SetDatabaseEnvConfig(cfg DatabaseEnvConfig)
- func SetEmitterLoggerFactory(factory func([]event.EventEmitter) event.EmitterLogger)
- func SetEnvVarConfig(cfg EnvVarConfig)
- func SetLoggerFactory(factory func(ctx context.Context) logging.ILogger)
- func SetLoggerPlainFactory(...)
- func SetServerEnvConfig(cfg ServerEnvConfig)
- func SetStackEnvConfig(cfg StackEnvConfig)
- func SetUUIDGenFactory(factory func() *UUIDGen)
- func StartServer(endpoints []endpoint.Endpoint) error
- func TxManager[T any]() db.TxManager[T]
- func ValidationRules() map[string]func(any) error
- func WrapCtxLoggerFactory(factoryFn logging.CtxLoggerFactoryFn) logging.LoggerFactoryFn
- type DatabaseEnvConfig
- type DriverProvider
- type EnvVarConfig
- type LoggingConfig
- type MySQLConfig
- type SQLiteConfig
- type ServerConfig
- type ServerEnvConfig
- type StackBuilder
- type StackConfig
- type StackEnvConfig
- type UUID
- type UUIDGen
Constants ¶
const ( SQLite3 = "sqlite3" MySQL = "mysql" )
Supported database drivers.
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 ¶
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 ¶
InputConversionRules returns the default input conversion rules.
Returns:
- map[string]func(any) any: The input conversion rules.
func LoggerPlain ¶
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 ¶
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 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 ¶
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 ¶
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 ¶
StartServer starts the server.
Parameters:
- endpoints: The endpoints to serve.
Returns:
- error: An error if the server fails to start.
func ValidationRules ¶
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 ¶
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 ¶
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 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 ¶
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 ¶
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 ¶
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 ¶
MustRandom returns a random UUID and panics on error.
Returns:
- UUID: A random UUID conforming to Version 4 and Variant 1.