Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Fixing Double anidbID (shoud also fix twice flags) + removed pointer to config in functions. We have a singleton so don't need to pass it as argument

Cette révision appartient à :
akuma06 2017-08-02 17:12:52 +02:00
Parent 78f8b90129
révision 94097dc2bb
5 fichiers modifiés avec 24 ajouts et 15 suppressions

Voir le fichier

@ -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

Voir le fichier

@ -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

18
main.go
Voir le fichier

@ -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()
}
}

Voir le fichier

@ -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)

Voir le fichier

@ -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)
}