You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.2 KiB
62 lines
1.2 KiB
|
1 year ago
|
package common
|
||
|
|
|
||
|
|
import (
|
||
|
|
"server/call"
|
||
|
|
"server/db"
|
||
|
|
"server/db/mysql"
|
||
|
|
rdb "server/db/redis"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
edb "server/db/es"
|
||
|
|
|
||
|
|
"github.com/liangdas/mqant/conf"
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
"github.com/liangdas/mqant/module"
|
||
|
|
basemodule "github.com/liangdas/mqant/module/base"
|
||
|
|
"github.com/liangdas/mqant/server"
|
||
|
|
)
|
||
|
|
|
||
|
|
type Call struct {
|
||
|
|
basemodule.BaseModule
|
||
|
|
}
|
||
|
|
|
||
|
|
var Module = func() module.Module {
|
||
|
|
this := new(Call)
|
||
|
|
return this
|
||
|
|
}
|
||
|
|
|
||
|
|
func (c *Call) GetType() string {
|
||
|
|
//很关键,需要与配置文件中的Module配置对应
|
||
|
|
return "common"
|
||
|
|
}
|
||
|
|
func (c *Call) Version() string {
|
||
|
|
//可以在监控时了解代码版本
|
||
|
|
return "1.0.0"
|
||
|
|
}
|
||
|
|
|
||
|
|
func (c *Call) OnInit(app module.App, settings *conf.ModuleSettings) {
|
||
|
|
c.BaseModule.OnInit(c, app, settings,
|
||
|
|
server.RegisterInterval(5*time.Second),
|
||
|
|
server.RegisterTTL(10*time.Second),
|
||
|
|
)
|
||
|
|
|
||
|
|
db.InitDB(&rdb.RedisClient{}, &edb.EsClient{}, &mysql.MysqlClient{})
|
||
|
|
|
||
|
|
call.NewCaller(c)
|
||
|
|
loadConfig()
|
||
|
|
initNats(c.App.Transport())
|
||
|
|
initTimer()
|
||
|
|
}
|
||
|
|
|
||
|
|
func (c *Call) Run(closeSig chan bool) {
|
||
|
|
log.Info("[%v]module running", c.GetType())
|
||
|
|
<-closeSig
|
||
|
|
log.Info("[%v]module stop", c.GetType())
|
||
|
|
}
|
||
|
|
|
||
|
|
func (c *Call) OnDestroy() {
|
||
|
|
//一定别忘了继承
|
||
|
|
c.BaseModule.OnDestroy()
|
||
|
|
log.Info("[%v]module destroy", c.GetType())
|
||
|
|
}
|