game_sync/mongo/export.go

59 lines
1.3 KiB
Go

package mongo
import (
"errors"
"mongo.games.com/game/mongo/internal"
"mongo.games.com/goserver/core/logger"
)
type Config = internal.Config
type DatabaseConfig = internal.DatabaseConfig
type Collection = internal.Collection
var _manager *internal.Manager
var _conf *internal.Config
// GetConfig 获取配置
func GetConfig() *Config {
return _conf
}
// Init 初始化
func Init(conf *Config) error {
_conf = conf
_manager = internal.NewManager(_conf)
return nil
}
// Restart 重启
func Restart() {
if _manager == nil {
logger.Logger.Errorf("mongo manager is nil, please call Init() first")
return
}
_manager.Restart(_conf)
}
// GetGlobalCollection 获取全局库
// database: 数据库名称
// collection: 集合名称
func GetGlobalCollection(database, collection string) (*Collection, error) {
if _manager == nil {
return nil, errors.New("mongo manager is nil, please call Init() first")
}
return _manager.GetCollection("global", database, collection)
}
// GetCollection 获取平台库
// platform: 平台id
// database: 数据库名称
// collection: 集合名称
func GetCollection(platform, database, collection string) (*Collection, error) {
if _manager == nil {
return nil, errors.New("mongo manager is nil, please call Init() first")
}
return _manager.GetCollection(platform, database, collection)
}