package main import ( "time" "github.com/go-xorm/xorm" ) // Database mysql数据结构 type Database struct { engine *xorm.Engine T struct { CountLiveAnchors *xorm.Session } } // 默认全局的数据库对象 var db *Database func databaseInit() { db := &Database{} // 初始化数据myrocks驱动链接 engine, err := xorm.NewEngine("mysql", "root:Nono-databoard@tcp(127.0.0.1:3306)/databoard?parseTime=true&loc=Local&charset=utf8&collation=utf8_unicode_ci") if err != nil { panic(err) } db.engine = engine // 数据库表对象 db.T.CountLiveAnchors = engine.Table("count_live_anchors") } // CountLiveAnchors count_live_anchors type CountLiveAnchors struct { UID string `xorm:"uid"` CreateAt time.Time `xorm:"create_at"` IsCounted int `xorm:"is_counted"` CountMap string `xorm:"count_map"` }