main.go 2.1 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
package main

import (
	"flag"
	"github.com/eolinker/goku/console/module/account"
	log "github.com/eolinker/goku/goku-log"

	"github.com/eolinker/goku/common/conf"
	"github.com/eolinker/goku/common/general"
	"github.com/eolinker/goku/console"
	"github.com/eolinker/goku/utils"
)

var (
	UserPassword string
	UserName     string
	ConfFilepath = "./config/goku.conf"

)

func main() {
	flag.StringVar(&ConfFilepath, "c", "./config/goku.conf", "Please provide a valid configuration file path")
	flag.StringVar(&UserName, "u", "", "Please provide user name")
	flag.StringVar(&UserPassword, "p", "", "Please provide user password")
	isDebug := flag.Bool("debug",false,"")

	flag.Parse()
	if *isDebug{
		log.StartDebug()
	}
	// 初始化配置
	if err := conf.ReadConfigure(ConfFilepath); err != nil {
		log.Panic(err)
		return
	}
	// 初始化db
	console.InitDatabase()
	console.InitLog()

	console.InitClusters()
	// 其他需要初始化的模块
	_ = general.General()
	// 检测是否安装


	if s, err := account.CheckSuperAdminCount(); err!= nil {
		log.Panic(err)
		return
	}else if s == 0 {
		if UserName == "" {
			log.Fatal("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
			//fmt.Println("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
			return
		}
		if UserPassword == "" {
			log.Fatal("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
			//fmt.Println("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
			return
		}

		// 用户注册
		password := utils.Md5(utils.Md5(UserPassword))
		f := console.Register(UserName, password)
		if !f {
			log.Fatal("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
			//fmt.Println("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
			return
		}
	}


	console.Router()
	console.Server()
}