main.go 2.3 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4
package main

import (
	"flag"
黄孟柱 已提交
5 6
	"github.com/eolinker/goku-api-gateway/console/module/account"
	log "github.com/eolinker/goku-api-gateway/goku-log"
E
eoLinker API Management 已提交
7

黄孟柱 已提交
8 9 10 11
	"github.com/eolinker/goku-api-gateway/common/conf"
	"github.com/eolinker/goku-api-gateway/common/general"
	"github.com/eolinker/goku-api-gateway/console"
	"github.com/eolinker/goku-api-gateway/utils"
E
eoLinker API Management 已提交
12 13 14
)

var (
Y
Your Name 已提交
15
	// UserPassword 用户密码
E
eoLinker API Management 已提交
16
	UserPassword string
Y
Your Name 已提交
17
	// UserName 用户名
E
eoLinker API Management 已提交
18
	UserName     string
Y
Your Name 已提交
19
	// ConfFilePath 配置文件地址
删除  
黄孟柱 已提交
20
	ConfFilePath = "./config/goku.conf"
E
eoLinker API Management 已提交
21 22 23 24

)

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

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

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

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