diff --git a/config/config.go b/config/config.go index bbd426c5..0dea0f95 100644 --- a/config/config.go +++ b/config/config.go @@ -60,7 +60,16 @@ func init() { func Reload() { fmt.Println("Config reload") fmt.Println(Configpaths) - configor.Load(Get(), Configpaths...) + newConf := &Config{ + DBType: Get().DBType, + Host: Get().Host, + Port: Get().Port, + DBParams: Get().DBParams, + DBLogMode: Get().DBLogMode, + } + config = newConf + configor.Load(config, Configpaths...) + fmt.Printf("Port: %d", Get().Port) } // BindFlags returns a function which is to be used after diff --git a/config/config_example.yml b/config/config_example.yml index 8e5ff374..b5097891 100644 --- a/config/config_example.yml +++ b/config/config_example.yml @@ -2,4 +2,4 @@ # Please, do not change default_config, create your own config.yml # You do not have to change every values, just set here what you want to edit # For example, if you just want to change the port, just write: -#port: 9998 +port: 9998 diff --git a/main.go b/main.go index fac53abf..46ea404f 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,8 @@ import ( var buildversion string // RunServer runs webapp mainloop -func RunServer(conf *config.Config) { +func RunServer() { + conf := config.Get() // TODO Use config from cli os.Mkdir(databasedumpsController.DatabaseDumpPath, 0700) // TODO Use config from cli @@ -59,18 +60,17 @@ func RunServer(conf *config.Config) { } func main() { - conf := config.Get() if buildversion != "" { - conf.Build = buildversion + config.Get().Build = buildversion } else { - conf.Build = "unknown" + config.Get().Build = "unknown" } defaults := flag.Bool("print-defaults", false, "print the default configuration file on stdout") callback := config.BindFlags() flag.Parse() if *defaults { stdout := bufio.NewWriter(os.Stdout) - err := conf.Pretty(stdout) + err := config.Get().Pretty(stdout) if err != nil { log.Fatal(err.Error()) } @@ -82,18 +82,18 @@ func main() { } else { callback() var err error - models.ORM, err = models.GormInit(conf, models.DefaultLogger) + models.ORM, err = models.GormInit(models.DefaultLogger) if err != nil { log.Fatal(err.Error()) } if config.Get().Search.EnableElasticSearch { models.ElasticSearchClient, _ = models.ElasticSearchInit() } - err = publicSettings.InitI18n(conf.I18n, cookies.NewCurrentUserRetriever()) + err = publicSettings.InitI18n(config.Get().I18n, cookies.NewCurrentUserRetriever()) if err != nil { log.Fatal(err.Error()) } - err = search.Configure(&conf.Search) + err = search.Configure(&config.Get().Search) if err != nil { log.Fatal(err.Error()) } @@ -104,6 +104,6 @@ func main() { log.Fatal(err.Error()) } } - RunServer(conf) + RunServer() } } diff --git a/models/gorm.go b/models/gorm.go index 506bbe7c..eee6c2d0 100644 --- a/models/gorm.go +++ b/models/gorm.go @@ -43,8 +43,8 @@ func ElasticSearchInit() (*elastic.Client, error) { } // GormInit init gorm ORM. -func GormInit(conf *config.Config, logger Logger) (*gorm.DB, error) { - +func GormInit(logger Logger) (*gorm.DB, error) { + conf := config.Get() db, openErr := gorm.Open(conf.DBType, conf.DBParams) if openErr != nil { log.CheckError(openErr) diff --git a/models/gorm_test.go b/models/gorm_test.go index 28f21182..a73a2348 100644 --- a/models/gorm_test.go +++ b/models/gorm_test.go @@ -39,7 +39,7 @@ func TestGormInitSqlite(t *testing.T) { config.Get().DBParams = ":memory:?cache=shared&mode=memory" config.Get().DBLogMode = "detailed" - db, err := GormInit(config.Get(), &errorLogger{t}) + db, err := GormInit(&errorLogger{t}) if err != nil { t.Errorf("failed to initialize database: %v", err) return @@ -82,7 +82,7 @@ func TestGormInitPostgres(t *testing.T) { config.Get().Models.UploadsOldTableName = "user_uploads_old" config.Get().Models.LastOldTorrentID = 90000 - db, err := GormInit(config.Get(), &errorLogger{t}) + db, err := GormInit(&errorLogger{t}) if err != nil { t.Errorf("failed to initialize database: %v", err) }