1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2025-07-02 04:18:38 -04:00

Move database configuration into config file

Also support mysql and postgres (at least in name, they haven't been
fully tested yet)
This commit is contained in:
2017-10-02 20:55:26 -04:00
parent 319b0b147d
commit 8ce3ef1bf5
4 changed files with 87 additions and 14 deletions

10
db.go
View File

@ -2,15 +2,17 @@ package main
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
"gopkg.in/gorp.v1"
"log"
)
var DB *gorp.DbMap = initDB()
var DB *gorp.DbMap
func initDB() *gorp.DbMap {
db, err := sql.Open("sqlite3", "file:moneygo.sqlite?cache=shared&mode=rwc")
func initDB(cfg *Config) {
db, err := sql.Open(cfg.MoneyGo.DBType.String(), cfg.MoneyGo.DSN)
if err != nil {
log.Fatal(err)
}
@ -30,5 +32,5 @@ func initDB() *gorp.DbMap {
log.Fatal(err)
}
return dbmap
DB = dbmap
}