first commit
This commit is contained in:
31
service/backend/dao/dao.go
Normal file
31
service/backend/dao/dao.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/inconshreveable/log15"
|
||||
"gitlab.33.cn/chat/dtalk/pkg/mysql"
|
||||
"gitlab.33.cn/chat/dtalk/service/backend/config"
|
||||
)
|
||||
|
||||
type Dao struct {
|
||||
log log15.Logger
|
||||
conn *mysql.MysqlConn
|
||||
}
|
||||
|
||||
func New(c *config.Config) *Dao {
|
||||
d := &Dao{
|
||||
log: log15.New("module", "backend/dao"),
|
||||
conn: newDB(c.MySQL),
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func newDB(cfg *config.MySQL) *mysql.MysqlConn {
|
||||
c, err := mysql.NewMysqlConn(cfg.Host, fmt.Sprintf("%v", cfg.Port),
|
||||
cfg.User, cfg.Pwd, cfg.Db, "UTF8MB4")
|
||||
if err != nil {
|
||||
log15.Error("mysql init failed", "err", err)
|
||||
panic(err)
|
||||
}
|
||||
return c
|
||||
}
|
||||
Reference in New Issue
Block a user