Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Prod = fx.Module(moduleName, fx.Decorate(func(l *zap.Logger) *zap.Logger { return l.Named(moduleName) }), fx.Provide(fx.Annotate( func(o env.Options) (c Config, err error) { o.Prefix = strings.ToUpper(moduleName) + "_" return c, env.Parse(&c, o) }, fx.ParamTags(`optional:"true"`))), fx.Provide(fx.Annotate(NewReadOnlyConfig, fx.ParamTags(``, ``, `optional:"true"`), fx.ResultTags(`name:"ro"`))), fx.Provide(fx.Annotate(NewReadWriteConfig, fx.ParamTags(``, ``, `optional:"true"`), fx.ResultTags(`name:"rw"`))), fx.Provide(fx.Annotate(New, fx.ParamTags(`name:"ro"`), fx.ResultTags(`name:"ro"`), fx.OnStart(func(ctx context.Context, in struct { fx.In DB *sql.DB `name:"ro"` }) error { return in.DB.PingContext(ctx) }), fx.OnStop(func(ctx context.Context, in struct { fx.In DB *sql.DB `name:"ro"` }) error { return in.DB.Close() }), )), fx.Provide(fx.Annotate(New, fx.ParamTags(`name:"rw"`), fx.ResultTags(`name:"rw"`), fx.OnStart(func(ctx context.Context, in struct { fx.In DB *sql.DB `name:"rw"` }) error { return in.DB.PingContext(ctx) }), fx.OnStop(func(ctx context.Context, in struct { fx.In DB *sql.DB `name:"rw"` }) error { return in.DB.Close() }), )), )
Prod configures the DI for providng database connectivity
View Source
var Test = fx.Options(Prod, fx.Decorate(func(cfg Config) Config { var b [8]byte rand.Read(b[:]) cfg.TemporarySchemaName = fmt.Sprintf(moduleName+"_test_%x", b[:]) return cfg }), fx.Provide(fx.Annotate(func(rw *sql.DB) *sql.DB { return rw }, fx.ParamTags(`name:"rw"`))), fx.Provide(fx.Annotate(func(rw *pgxpool.Config) *pgxpool.Config { return rw }, fx.ParamTags(`name:"rw"`))), )
Test configures the DI for a test environment
Functions ¶
func NewReadOnlyConfig ¶
NewReadOnlyConfig constructs a config for a read-only database connecion. The aws config is optional and is only used when IamAuth option is set.
Types ¶
type Config ¶
type Config struct { // DatabaseName names the database the connection will be made to DatabaseName string `env:"DATABASE_NAME" envDefault:"postgres"` // ReadWriteHostname endpoint allows configuration of a endpoint that can read and write ReadWriteHostname string `env:"RW_HOSTNAME" envDefault:"localhost"` // ReadOnlyHostname endpoint allows configuration of a endpoint that can read and write ReadOnlyHostname string `env:"RW_HOSTNAME" envDefault:"localhost"` // Port for to the database connection(s) Port int `env:"PORT" envDefault:"5432"` // Username configures the username to connect to the postgres instance Username string `env:"USERNAME" envDefault:"postgres"` // Password configures the postgres password for authenticating with the instance Password string `env:"PASSWORD"` // IamAuthTimeout bounds the time it takes to geht the IAM auth token IamAuthTimeout time.Duration `env:"IAM_AUTH_TIMEOUT" envDefault:"100ms"` // PgxLogLevel is provided to pgx to determine the level of logging of postgres interactions PgxLogLevel string `env:"PGX_LOG_LEVEL" envDefault:"info"` // SchemaName sets the schema to which the connections search_path will be set SchemaName string `env:"SCHEMA_NAME" envDefault:"public"` // TemporarySchemaName can be set to non-empty to cause schema name to indicate it is temporary schema TemporarySchemaName string `env:"TEMPORARY_SCHEMA_NAME"` // SSLMode sets tls encryption on the database connection SSLMode string `env:"SSL_MODE" envDefault:"disable"` }
Config configures the code in this package.
Click to show internal directories.
Click to hide internal directories.