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
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
删除  
黄孟柱 已提交
17
	ConfFilePath = "./config/goku.conf"
E
eoLinker API Management 已提交
18 19 20 21

)

func main() {
删除  
黄孟柱 已提交
22
	flag.StringVar(&ConfFilePath, "c", "./config/goku.conf", "Please provide a valid configuration file path")
E
eoLinker API Management 已提交
23 24
	flag.StringVar(&UserName, "u", "", "Please provide user name")
	flag.StringVar(&UserPassword, "p", "", "Please provide user password")
Y
Your Name 已提交
25
	isDebug := flag.Bool("debug", false, "")
E
eoLinker API Management 已提交
26 27

	flag.Parse()
Y
Your Name 已提交
28
	if *isDebug {
E
eoLinker API Management 已提交
29 30 31
		log.StartDebug()
	}
	// 初始化配置
删除  
黄孟柱 已提交
32
	if err := conf.ReadConfigure(ConfFilePath); err != nil {
E
eoLinker API Management 已提交
33 34 35 36 37 38 39 40 41 42 43 44
		log.Panic(err)
		return
	}
	// 初始化db
	console.InitDatabase()
	console.InitLog()

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

Y
Your Name 已提交
45
	if s, err := account.CheckSuperAdminCount(); err != nil {
E
eoLinker API Management 已提交
46 47
		log.Panic(err)
		return
Y
Your Name 已提交
48
	} else if s == 0 {
E
eoLinker API Management 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
		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()
}