config

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: May 27, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const Postgres = "postgres"

Variables

This section is empty.

Functions

func OpenDbConnection

func OpenDbConnection(config DbConnectionConfigProvider) (*gorm.DB, error)

Opens a connection to the database specified in the config. You must call CloseDbConnection at the end of your session!

Types

type BaseConfig

type BaseConfig struct {
	LogLevel                                 logger.LogLevel `json:"log_level"`
	DisableForeignKeyConstraintWhenMigrating bool
}

type DbConfig

type DbConfig struct {
	BaseConfig
	Host         string `json:"host"`
	Port         int    `json:"port"`
	DbName       string `json:"dbname"`
	User         string `json:"user"`
	Password     string `json:"password"`
	ExtraOptions string `json:"options"`
}

Database config. Contains values necessary to open a database connection.

type DbConfigSection

type DbConfigSection struct {
	Host   string `json:"host"`
	Port   int    `json:"port"`
	DbName string `json:"dbname"`
	User   string `json:"username"`
	// Either Password or PasswordPath must be set.
	Password     string `json:"password"`
	PasswordPath string `json:"passwordPath"`
	// See http://gorm.io/docs/connecting_to_the_database.html for available options passed, in addition to the above.
	ExtraOptions string          `json:"options"`
	LogLevel     logger.LogLevel `json:"log_level"`
}

This struct corresponds to the database section of in the config

func (DbConfigSection) GetPFlagSet

func (cfg DbConfigSection) GetPFlagSet(prefix string) *pflag.FlagSet

GetPFlagSet will return strongly types pflags for all fields in DbConfigSection and its nested types. The format of the flags is json-name.json-sub-name... etc.

type DbConnectionConfigProvider

type DbConnectionConfigProvider interface {
	// Returns database dialector
	GetDialector() gorm.Dialector

	GetDBConfig() DbConfig

	GetDSN() string
}

Generic interface for providing a config necessary to open a database connection.

func NewPostgresConfigProvider

func NewPostgresConfigProvider(config DbConfig, scope promutils.Scope) DbConnectionConfigProvider

TODO : Make the Config provider itself env based

type PostgresConfigProvider

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

PostgreSQL implementation for DbConnectionConfigProvider.

func (*PostgresConfigProvider) GetDBConfig added in v0.3.5

func (p *PostgresConfigProvider) GetDBConfig() DbConfig

func (*PostgresConfigProvider) GetDSN added in v0.3.5

func (p *PostgresConfigProvider) GetDSN() string

func (*PostgresConfigProvider) GetDialector added in v0.3.5

func (p *PostgresConfigProvider) GetDialector() gorm.Dialector

Jump to

Keyboard shortcuts

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