Commit 98feb121 authored by vicotor's avatar vicotor

add dbinit

parent 23ed2b25
......@@ -4,6 +4,7 @@ import (
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
"github.com/odysseus/nodemanager/config"
"github.com/odysseus/nodemanager/metrics"
"github.com/odysseus/nodemanager/model"
"github.com/odysseus/nodemanager/server"
"github.com/rifflock/lfshook"
log "github.com/sirupsen/logrus"
......@@ -69,6 +70,7 @@ func initConfig() {
}
func runNode() {
model.DbInit()
n := server.NewNode()
if err := n.Start(); err != nil {
log.WithError(err).Error("run node failed")
......
......@@ -8,7 +8,7 @@ password="123456"
db=0
[mysql]
host="127.0.0.1"
host="192.168.1.211"
port=3306
user="root"
password="12345678"
......
......@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/astaxie/beego/orm"
"github.com/odysseus/nodemanager/config"
log "github.com/sirupsen/logrus"
)
func DbInit() {
......@@ -11,6 +12,9 @@ func DbInit() {
dbconf := config.GetConfig().DbConfig
datasource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbconf.User, dbconf.Passwd, dbconf.Host, dbconf.Port, dbconf.DbName)
orm.RegisterDriver("mysql", orm.DRMySQL)
orm.RegisterDataBase("default", "mysql", datasource)
err := orm.RegisterDataBase("default", "mysql", datasource)
if err != nil {
log.WithError(err).Fatal("failed to connect to database")
}
orm.RegisterModel(new(User))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment