Giter Club home page Giter Club logo

Comments (3)

thetooth avatar thetooth commented on May 13, 2024

Here is my take, this also addresses the issue in config.go where non-defaults aren't applied if you don't give it a config file:

diff --git a/config/config.go b/config/config.go
index d7597ec..bc2d377 100644
--- a/config/config.go
+++ b/config/config.go
@@ -50,16 +50,21 @@ func (config *Config) BindFlags() processFlags {
 	db_params := flag.String("dbparams", Defaults.DBParams, "parameters to open the database (see Gorm's doc)")
 
 	return func() error {
-		err := config.HandleConfFileFlag(*conf_file)
-		if err != nil {
-			return err
-		}
+
 		// You can override fields in the config file with flags.
 		config.Host = *host
 		config.Port = *port
 		config.DBParams = *db_params
-		err = config.SetDBType(*db_type)
-		return err
+		err := config.SetDBType(*db_type)
+		if err != nil {
+			return err
+		}
+		err = config.HandleConfFileFlag(*conf_file)
+		if err != nil {
+			return err
+		}
+
+		return nil
 	}
 }
 
diff --git a/db/gorm.go b/db/gorm.go
index 42ba2bf..693352e 100644
--- a/db/gorm.go
+++ b/db/gorm.go
@@ -2,18 +2,17 @@ package db
 
 import (
 	"github.com/ewhal/nyaa/config"
-	"github.com/ewhal/nyaa/util/log"
 	"github.com/ewhal/nyaa/model"
+	"github.com/ewhal/nyaa/util/log"
 	"github.com/jinzhu/gorm"
 	_ "github.com/jinzhu/gorm/dialects/sqlite"
 	// _ "github.com/go-sql-driver/mysql"
 )
 
-var ORM, Errs = GormInit()
+var ORM *gorm.DB
 
 // GormInit init gorm ORM.
-func GormInit() (*gorm.DB, error) {
-	conf := config.NewConfig()
+func GormInit(conf *config.Config) (*gorm.DB, error) {
 	db, err := gorm.Open(conf.DBType, conf.DBParams)
 	// db, err := gorm.Open("mysql", config.MysqlDSL())
 	//db, err := gorm.Open("sqlite3", "/tmp/gorm.db")
diff --git a/main.go b/main.go
index 7b91acf..88ba666 100755
--- a/main.go
+++ b/main.go
@@ -6,6 +6,7 @@ import (
 	"fmt"
 
 	"github.com/ewhal/nyaa/config"
+	"github.com/ewhal/nyaa/db"
 	"github.com/ewhal/nyaa/router"
 	"github.com/ewhal/nyaa/util/log"
 
@@ -39,7 +40,8 @@ func main() {
 		stdout.Flush()
 		os.Exit(0)
 	} else {
-		conf_bind()
+		_ = conf_bind()
+		db.ORM, _ = db.GormInit(conf)
 		RunServer(conf)
 	}
 }

from nyaa.

s-varezhkin avatar s-varezhkin commented on May 13, 2024

None of the parameters are working. Gonna fix it in a few minutes.

from nyaa.

s-varezhkin avatar s-varezhkin commented on May 13, 2024

Should be working in 86049d8

from nyaa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.