summaryrefslogtreecommitdiff
path: root/db.go
blob: ccddd000411ec1e00507996dbc5515a096d1e423 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main

import (
	"kch42.de/gostuff/mailremind/model"
	"log"
)

var db model.DBInfo
var dbcon model.DBCon

func initDB() {
	dbdrv, err := conf.GetString("db", "driver")
	if err != nil {
		log.Fatalf("Could not get db.driver from config: %s", err)
	}

	dbconf, err := conf.GetString("db", "conf")
	if err != nil {
		log.Fatalf("Could not get db.conf from config: %s", err)
	}

	var ok bool
	if db, ok = model.GetDBInfo(dbdrv); !ok {
		log.Fatalf("Could not get info for dbdrv %s: %s", dbdrv, err)
	}

	if dbcon, err = db.Connect(dbconf); err != nil {
		log.Fatalf("Unable to connect to %s database: %s", dbdrv, err)
	}
}