Add dbName config.

This commit is contained in:
Yang Luo
2021-02-15 10:11:26 +08:00
parent e71311b1af
commit e4778b967f
2 changed files with 4 additions and 2 deletions

View File

@ -4,5 +4,6 @@ runmode = dev
SessionOn = true SessionOn = true
copyrequestbody = true copyrequestbody = true
dataSourceName = root:123@tcp(localhost:3306)/ dataSourceName = root:123@tcp(localhost:3306)/
dbName = casdoor
AuthState = "casdoor" AuthState = "casdoor"
UseProxy = false UseProxy = false

View File

@ -15,6 +15,7 @@
package object package object
import ( import (
"fmt"
"runtime" "runtime"
"github.com/astaxie/beego" "github.com/astaxie/beego"
@ -65,7 +66,7 @@ func (a *Adapter) createDatabase() error {
} }
defer engine.Close() defer engine.Close()
_, err = engine.Exec("CREATE DATABASE IF NOT EXISTS casdoor default charset utf8 COLLATE utf8_general_ci") _, err = engine.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s default charset utf8 COLLATE utf8_general_ci", beego.AppConfig.String("dbName")))
return err return err
} }
@ -74,7 +75,7 @@ func (a *Adapter) open() {
panic(err) panic(err)
} }
engine, err := xorm.NewEngine(a.driverName, a.dataSourceName+"casdoor") engine, err := xorm.NewEngine(a.driverName, a.dataSourceName+beego.AppConfig.String("dbName"))
if err != nil { if err != nil {
panic(err) panic(err)
} }