Documentation
¶
Overview ¶
Package config provides a flexible configuration management type, allowing for the usage of YAML files or environment variables. For details on how the environment variable based configuration works please see https://github.com/vrischmann/envconfig#how-does-it-work however a basic example is included below ``` var conf struct { Name string Shard struct { Host string Port int } } ``` The above struct will check for the following keys: * NAME or name * SHARD_HOST, or shard_host * SHARD_PORT, or shard_port
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ExampleConfig is primarily used to provide a template for generating the config file ExampleConfig = &Config{ Database: Database{ Type: "sqlite", Host: "localhost", Port: "5432", User: "postgres", Pass: "password123", DBName: "go-template", DBPath: "", SSLModeDisable: false, }, Logger: Logger{ Path: "go-template.log", Debug: true, Dev: true, }, } )
Functions ¶
Types ¶
type Config ¶
Config provides the base configuration type
func LoadConfig ¶
LoadConfig loads the configuration at path however if loading from path fails, we attempt to load from environment variabels
type Database ¶
type Database struct { // Type specifies the database type to be used // currently supports: sqlite, postgres // when using sqlite type all other options except DBName and DBPath are ignore Type string `yaml:"type"` // Host specifies the database host address Host string `yaml:"host" envconfig:"optional"` // Port specifies the port the database is exposed on Port string `yaml:"port" envconfig:"optional"` // User specifies the username to use for authentication User string `yaml:"user" envconfig:"optional"` // Pass specifies the password to use for authentication Pass string `yaml:"pass" envconfig:"optional"` // DBName specifies the name of the database DBName string `yaml:"db_name"` // DBPath specifies the path to the database file (only applicable to sqlite) DBPath string `yaml:"db_path" envconfig:"optional"` // SSLModeDisable specifies whether or not to disable ssl connection layer security SSLModeDisable bool `yaml:"ssl_mode_disable" envconfig:"optional"` }
Database provides configuration over our database connection
type Logger ¶
type Logger struct { // Path to store the configuration file Path string `yaml:"path" envconfig:"default=go-template.log"` // Debug enables displaying of debug logs Debug bool `yaml:"debug" envconfig:"optional"` // Dev enables foramtting of logs to be more human readable Dev bool `yaml:"dev" envconfig:"optional"` // FileOnly disables stdout logging and will only display log output in `Path` FileOnly bool `yaml:"file_only" envconfig:"optional"` // Fields provides optional fields to use for logging metadata Fields map[string]interface{} `yaml:"fields" envconfig:"optional"` }
Logger provides configuration over zap logger
Click to show internal directories.
Click to hide internal directories.