[TASK] add database support
This commit is contained in:
parent
75a378a0cd
commit
eb75db5989
|
@ -1,16 +1,14 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||
)
|
||||
|
||||
var (
|
||||
Write *gorm.Database
|
||||
Read *gorm.Database
|
||||
Write *gorm.DB
|
||||
Read *gorm.DB
|
||||
config *Config
|
||||
models []interface{}
|
||||
)
|
||||
|
@ -22,7 +20,7 @@ type Config struct {
|
|||
ReadConnection string
|
||||
}
|
||||
|
||||
func Open(c Config) (err errors.Error) {
|
||||
func Open(c Config) (err error) {
|
||||
config = &c
|
||||
Write, err = gorm.Open(config.Type, config.Connection)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
package database
|
||||
|
||||
|
||||
|
|
|
@ -12,11 +12,7 @@ import (
|
|||
//Config the config File of this daemon
|
||||
type Config struct {
|
||||
WebserverBind string
|
||||
Database struct {
|
||||
Type string
|
||||
Connection string
|
||||
ReadConnection string
|
||||
}
|
||||
Database database.Config
|
||||
}
|
||||
|
||||
// ReadConfigFile reads a config model from path of a yml file
|
||||
|
|
Reference in New Issue