// main
package main

import (
	"crypto/md5"
	"encoding/hex"
	"front"
	"log"

	qu "qfw/util"
	"strings"
	"util"

	"github.com/go-xweb/xweb"
)

func MD5(appid, t, secret string) string {
	h := md5.New()
	h.Write([]byte(appid + t + secret))
	return strings.ToUpper(hex.EncodeToString(h.Sum(nil)))
}
func init() {
	//log.Println(MD5("jynw166_fEs2021", "1617340065", "Tgb#8diO90L"))
	//os.Exit(0)
	qu.ReadConfig(&util.Config)
	util.InitConfig()
	//util.InitInfluxdb(util.Config.InfluxdbUrl)
	//redis
	//redis.InitRedis(util.Config.Redis)
	//oss
	util.InitOss()
	//xweb框架配置
	xweb.Config.RecoverPanic = true
	xweb.Config.Profiler = true
	xweb.RootApp().AppConfig.TemplateDir = "web/templates"
	xweb.RootApp().AppConfig.StaticDir = "web/staticres"
	xweb.RootApp().AppConfig.StaticFileVersion = false
	xweb.RootApp().AppConfig.CheckXsrf = false
	xweb.RootApp().AppConfig.ReloadTemplates = false
	xweb.RootApp().AppConfig.EnableHttpCache = false
	xweb.RootApp().AppConfig.Mode = xweb.Product
	xweb.RootApp().AppConfig.CacheTemplates = false
	xweb.AddAction(&front.Front{})
	//_id初始化内存
	log.Println("_id初始化内存...")
	//front.IdList = list.New()

	//加载所有数据，存入IdList
	//ls, _ := util.MgoM.Find(util.Config.Fromtable, `{"check":{"$exists":0}}`, nil, `{"_id":1}`, false, -1, -1)
	//ls, _ := util.MgoM.Find(util.Coll, nil, nil, `{"_id":1}`, false, -1, -1)
	//for _, v := range *ls {
	//	front.IdList.PushBack(mgo.BsonIdToSId(v["_id"]))
	//}
	//qu.Debug("_id初始化内存完成", front.IdList.Len())
	// front.IdPackList = list.New()
	// //加载所有未标注数据且含有分包信息的数据
	// lspack, _ := util.MgoM.Find(util.Config.Fromtable, `{"check":{"$exists":0},"package":{"$exists":1}}`, nil, `{"_id":1}`, false, -1, -1)
	// for _, v := range *lspack {
	// 	front.IdPackList.PushBack(mgo.BsonIdToSId(v["_id"]))
	// }
	// log.Println("_id初始化内存完成_分包", front.IdPackList.Len())
}

func main() {
	xweb.Run(":" + util.Config.Port)
}
