Documentation ¶
Index ¶
- func NewDBFlagSet() *pflag.FlagSet
- func NewFlagSet() *pflag.FlagSet
- func NewRootFlagSet() *pflag.FlagSet
- func NewServerFlagSet() *pflag.FlagSet
- func UnmarshalAppConfig(cfg interface{}, v *viper.Viper) error
- func ValidateDBConfig(cfg DBConfig) error
- type AppConfig
- type Config
- type DBConfig
- type Mapping
- type Mappings
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDBFlagSet ¶
NewDBFlagSet returns a list of flags contained within the [db] section of a config
func NewFlagSet ¶
NewFlagSet creates the set of flags specific to the server and db config and the root level config (like --version, --env)
func NewRootFlagSet ¶
NewRootFlagSet returns a list of top level flags (flags that arent contained inside an environment section in the config)
func NewServerFlagSet ¶
NewServerFlagSet returns a list of flags contained within the [server] section of a config
func UnmarshalAppConfig ¶
UnmarshalAppConfig unmarshals the viper's configured config file into the passed in cfg object containing an AppConfig
func ValidateDBConfig ¶
ValidateDBConfig returns an error if any of the required db config fields are not set to their appropriate values.
Types ¶
type AppConfig ¶
type AppConfig struct { // The active environment section Env string `toml:"env" mapstructure:"env" env:"ENV"` Server ServerConfig `toml:"server" mapstructure:"server"` DB DBConfig `toml:"db" mapstructure:"db"` }
AppConfig struct includes the necessary abcweb config components. If you'd rather use your own struct so that you can add new values to your configuration you can do so, but make sure you include *ServerConfig objects and *DBConfig objects like below (if desired).
If you do not wish to use a database then you can exclude the DBConfig struct in your own struct, but if using this AppConfig struct then DBConfig MUST be initialized and database configuration must be present.
type Config ¶
type Config struct { // The config file path, overwritten in tests to point to a tmp file File string // Specify which environment to load, empty string means pull the // env from the configuration file, cmdline and env vars. LoadEnv string // Prefix the environment variables with this name so that the config // variables don't conflict with other abcweb apps EnvPrefix string }
Config object used to initialize configuration
func (*Config) Bind ¶
Bind your passed in config flags to a new viper instance, retrieves the active environment section of your config file using that viper instance, and then loads your server and db config into the passed in cfg struct and validates the db config is set appropriately.
func (*Config) ConfigureViper ¶
ConfigureViper sets the viper object to use the passed in config toml file and also configures the configuration environment variables.
func (*Config) NewSubViper ¶
NewSubViper returns a viper instance activated against the active environment configuration subsection and initialized with the config.toml configuration file and the environment variable prefix. It also takes in the configuration struct so that it can generate the env mappings.
type DBConfig ¶
type DBConfig struct { // DebugMode is a flag to toggle the output of SQLBoiler's SQL queries DebugMode bool `toml:"debug-mode" mapstructure:"debug-mode" env:"DB_DEBUG_MODE"` // DB is the database software; "postgres", "mysql", etc. DB string `toml:"db" mapstructure:"db" env:"DB_DB"` // The database name DBName string `toml:"dbname" mapstructure:"dbname" env:"DB_DBNAME"` Host string `toml:"host" mapstructure:"host" env:"DB_HOST"` Port int `toml:"port" mapstructure:"port" env:"DB_PORT"` User string `toml:"user" mapstructure:"user" env:"DB_USER"` Pass string `toml:"pass" mapstructure:"pass" env:"DB_PASS"` SSLMode string `toml:"sslmode" mapstructure:"sslmode" env:"DB_SSLMODE"` // Throw an error when the app starts if the database is not // using the latest migration EnforceMigration bool `toml:"enforce-migration" mapstructure:"enforce-migration" env:"DB_ENFORCE_MIGRATION"` }
DBConfig holds the database config for the app loaded through environment variables, or the config.toml file.
type Mapping ¶
type Mapping struct {
// contains filtered or unexported fields
}
Mapping represents a chain which is a list of nested object mapstructures joined together and seperated by dots (i.e. one.two.three), and the accompanying environment variable tag value for the last item in the chain
type Mappings ¶
type Mappings []Mapping
Mappings is a slice of mapping
func GetTagMappings ¶
GetTagMappings returns the viper .BindEnv mappings for an entire config struct.
type ServerConfig ¶
type ServerConfig struct { // LiveReload enabled or disabled LiveReload bool `toml:"live-reload" mapstructure:"live-reload" env:"SERVER_LIVE_RELOAD"` // Use the production logger (JSON and log level warn) or the // development logger (console and log level info) ProdLogger bool `toml:"prod-logger" mapstructure:"prod-logger" env:"SERVER_PROD_LOGGER"` // http bind address. ":<port>" for all interfaces Bind string `toml:"bind" mapstructure:"bind" env:"SERVER_BIND"` // https bind address. ":<port>" for all interfaces TLSBind string `toml:"tls-bind" mapstructure:"tls-bind" env:"SERVER_TLS_BIND"` // TLS certificate file path TLSCertFile string `toml:"tls-cert-file" mapstructure:"tls-cert-file" env:"SERVER_TLS_CERT_FILE"` // TLS key file path TLSKeyFile string `toml:"tls-key-file" mapstructure:"tls-key-file" env:"SERVER_TLS_KEY_FILE"` // Maximum duration before timing out read of the request ReadTimeout time.Duration `toml:"read-timeout" mapstructure:"read-timeout" env:"SERVER_READ_TIMEOUT"` // Maximum duration before timing out write of the response WriteTimeout time.Duration `toml:"write-timeout" mapstructure:"write-timeout" env:"SERVER_WRITE_TIMEOUT"` // Maximum duration before timing out idle keep-alive connection IdleTimeout time.Duration `toml:"idle-timeout" mapstructure:"idle-timeout" env:"SERVER_IDLE_TIMEOUT"` // Use manifest.json assets mapping AssetsManifest bool `toml:"assets-manifest" mapstructure:"assets-manifest" env:"SERVER_ASSETS_MANIFEST"` // Disable browsers caching asset files by setting response headers AssetsNoCache bool `toml:"assets-no-cache" mapstructure:"assets-no-cache" env:"SERVER_ASSETS_NO_CACHE"` // RenderRecompile enables recompilation of the template on every render call. // This should be used in development mode so no server restart is required // on template file changes. RenderRecompile bool `toml:"render-recompile" mapstructure:"render-recompile" env:"SERVER_RENDER_RECOMPILE"` // Use the development mode sessions storer opposed to production mode storer // defined in app/sessions.go -- Usually a cookie storer for dev // and disk storer for prod. SessionsDevStorer bool `toml:"sessions-dev-storer" mapstructure:"sessions-dev-storer" env:"SERVER_SESSIONS_DEV_STORER"` // PublicPath defaults to "public" but can be set to something else // by the {{.AppEnvName}}_SERVER_PUBLIC_PATH environment variable. // This is set by the "abcweb dev" command to instruct the app to // load assets from a /tmp folder instead of the local public folder. PublicPath string `toml:"public-path" mapstructure:"public-path" env:"SERVER_PUBLIC_PATH"` }
ServerConfig is config for the app loaded through environment variables, command line, or the config.toml file.