package internal

import (
	"github.com/name5566/leaf/module"
	"server/src/base"
	"server/src/conf"
	"server/src/internal/db"
	"time"
)

var (
	skeleton = base.NewSkeleton()
	ChanRPC  = skeleton.ChanRPCServer

	// mongo连接池
	mongoPool = &db.MongoPool{}
)

type Module struct {
	*module.Skeleton
}

func (m *Module) OnInit() {
	m.Skeleton = skeleton

	// mongo连接池初始化
	mongoPool.Init(db.MongoConfig{
		Host:     conf.MongoHost,
		Port:     conf.MongoPort,
		Username: conf.MongoUser,
		Password: conf.MongoPwd,
	}, conf.MongoPoolNum, 5*time.Second)
}

func (m *Module) OnDestroy() {
	mongoPool.Disconnect()
}
