Initial commit
This commit is contained in:
commit
c0cb826917
63 changed files with 2069 additions and 0 deletions
41
internal/infrastructure/config.go
Normal file
41
internal/infrastructure/config.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package infrastructure
|
||||
|
||||
import (
|
||||
"github.com/creasty/defaults"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
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/"`
|
||||
}
|
||||
|
||||
func LoadConfig() (config Config, err error) {
|
||||
config = Config{}
|
||||
if err = defaults.Set(config); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath(".")
|
||||
viper.AddConfigPath("/etc/58team_blog/")
|
||||
viper.AddConfigPath("/58team_blog/cfgs/")
|
||||
|
||||
if err = viper.ReadInConfig(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = viper.Unmarshal(&config); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue