package init

import (
	MC "app.yhyue.com/moapp/jybase/common"
	"flag"
	"github.com/zeromicro/go-zero/core/conf"
	"jyBXBuyer/api/internal/config"
	"log"
	"regexp"
)

var configFile = flag.String("cf", "etc/bxbuyer-api.yaml", "the config file")

var C config.Config

var dbFile = flag.String("df", "etc/db.yaml", "the db file")
var DB config.Db

var routesFile = flag.String("rf", "etc/routes.yaml", "the routes file")
var Routes config.Routes
var ExcludeUrl = []*regexp.Regexp{}

func init() {
	log.Println("初始化配置")
	//读取基础配置
	conf.MustLoad(*configFile, &C)
	//读取数据库配置
	conf.MustLoad(*dbFile, &DB)
	//初始mongodb
	MongoDBInit(&DB.Mongo)
	//读取路由配置
	conf.MustLoad(*routesFile, &Routes)
	if len(Routes.ExcludeRoute) > 0 {
		for _, v := range Routes.ExcludeRoute {
			ExcludeUrl = append(ExcludeUrl, regexp.MustCompile(MC.ObjToString(v)))
		}
	}
}
