Added: Dockerfile, support for configurations from env
This commit is contained in:
parent
ea8ab7c0ed
commit
c1ed822293
3 changed files with 117 additions and 10 deletions
|
|
@ -6,15 +6,14 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
DBUser string `mapstructure:"db-user" default:"userpg"`
|
||||
DBName string `mapstructure:"db-name" default:"58blog"`
|
||||
DBPass string `mapstructure:"db-password" default:"1205"`
|
||||
DBHost string `mapstructure:"db-host" default:"localhost"`
|
||||
DBPort string `mapstructure:"db-port" default:"5432"`
|
||||
AdminName string `mapstructure:"admin_name" default:"muts"`
|
||||
AdminPassword string `mapstructure:"admin_pass" default:"1205"`
|
||||
ImagesPath string `mapstructure:"images_path" default:"./images/"`
|
||||
PostsPath string `mapstructure:"posts_path" default:"./posts/"`
|
||||
DBUser string `mapstructure:"DBUser" default:"userpg"`
|
||||
DBName string `mapstructure:"DBName" default:"58blog"`
|
||||
DBPass string `mapstructure:"DBPassword" default:"1205"`
|
||||
DBHost string `mapstructure:"DBHost" default:"localhost"`
|
||||
DBPort string `mapstructure:"DBPort" default:"5432"`
|
||||
AdminName string `mapstructure:"ADMIN_NAME" default:"muts"`
|
||||
AdminPassword string `mapstructure:"ADMIN_PASS" default:"1205"`
|
||||
ImagesPath string `mapstructure:"IMAGES_PATH" default:"./images/"`
|
||||
}
|
||||
|
||||
func LoadConfig() (config *Config, err error) {
|
||||
|
|
@ -28,9 +27,12 @@ func LoadConfig() (config *Config, err error) {
|
|||
viper.AddConfigPath(".")
|
||||
viper.AddConfigPath("/etc/58team_blog/")
|
||||
viper.AddConfigPath("/58team_blog/cfgs/")
|
||||
viper.AutomaticEnv()
|
||||
|
||||
if err = viper.ReadInConfig(); err != nil {
|
||||
return nil, err
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if err = viper.Unmarshal(&config); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue