package util

import (
	"log"
	qu "qfw/util"
)

var (
	Sysconfig 		map[string]interface{}
	ExtMgo,SaveMgo  *MongodbSim //抽取初始化-相关
	ExtColl,CheckColl,SaveColl		string
	SF 	map[string]interface{}
)


func InitExt() {
	qu.ReadConfig(&Sysconfig)
	log.Println(Sysconfig)
	if len(Sysconfig) == 0 {
		log.Fatalln("init config err")
	}
	SF = *qu.ObjToMap(Sysconfig["source_field"])
	initMgo()
}
func initMgo () {
	saveconf := Sysconfig["save_mgodb"].(map[string]interface{})
	SaveColl = qu.ObjToString(saveconf["coll"])
	SaveMgo = &MongodbSim{
		MongodbAddr: saveconf["addr"].(string),
		DbName:      saveconf["db"].(string),
		Size:        qu.IntAllDef(saveconf["pool"], 5),
		UserName: 	saveconf["user"].(string),
		PassWord: 	saveconf["password"].(string),
	}
	SaveMgo.InitPool()

	//初始化mgo
	extconf := Sysconfig["ext_mgodb"].(map[string]interface{})
	ExtColl = qu.ObjToString(extconf["ext_coll"])
	CheckColl = qu.ObjToString(extconf["check_coll"])
	ExtMgo = &MongodbSim{
		MongodbAddr: extconf["addr"].(string),
		DbName:      extconf["db"].(string),
		Size:        qu.IntAllDef(extconf["pool"], 5),
		UserName: 	saveconf["user"].(string),
		PassWord: 	saveconf["password"].(string),
	}
	ExtMgo.InitPool()
}

