// main
package main

import (
	"log"
	mu "mfw/util"
	qu "qfw/util"
	"qfw/util/mongodb"

	"./service"
)

func init() {
	qu.ReadConfig(&service.Sysconfig)
	mongodbs, ok := service.Sysconfig["mongodbs"].(map[string]interface{})
	if ok {
		service.Mogdbs = make(map[string]service.MongoTool)
		for k, v := range mongodbs {
			if db, ok := v.(map[string]interface{}); ok {
				mongoTool := mongodb.MongodbSim{
					MongodbAddr: db["servers"].(string),
					Size:        qu.IntAll(db["size"]),
					DbName:      db["name"].(string),
				}
				mongoTool.InitPool()
				mdb := service.MongoTool{
					Mongodb: mongoTool,
					Name:    db["name"].(string),
					Coll:    db["coll"].(string),
				}
				service.Mogdbs[k] = mdb
			}
		}
		log.Println("mongodbs 初始化完成")
	} else {
		log.Fatal("mongodbs 初始化失败")
	}
}

func main() {
	updport := service.Sysconfig["udpport"].(string)
	service.Udpclient = mu.UdpClient{Local: updport, BufSize: 1024}
	service.Udpclient.Listen(service.ProcessUdpMsg)
	log.Println("Udp服务监听", updport)
	lock := make(chan bool)
	<-lock
}
