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

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

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

var (
Y
Your Name 已提交
14 15 16
	userPassword string
	userName     string
	confFilePath = "./config/goku.conf"
E
eoLinker API Management 已提交
17 18 19
)

func main() {
Y
Your Name 已提交
20 21 22
	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")
Y
Your Name 已提交
23
	isDebug := flag.Bool("debug", false, "")
E
eoLinker API Management 已提交
24 25

	flag.Parse()
Y
Your Name 已提交
26
	if *isDebug {
E
eoLinker API Management 已提交
27 28 29
		log.StartDebug()
	}
	// 初始化配置
Y
Your Name 已提交
30
	if err := conf.ReadConfigure(confFilePath); err != nil {
E
eoLinker API Management 已提交
31 32 33
		log.Panic(err)
		return
	}
Y
Your Name 已提交
34 35


E
eoLinker API Management 已提交
36
	// 初始化db
Y
Your Name 已提交
37 38
	InitDatabase()
	InitLog()
E
eoLinker API Management 已提交
39 40 41 42

	// 其他需要初始化的模块
	_ = general.General()
	// 检测是否安装
Y
Your Name 已提交
43 44 45 46
	s, err := account.CheckSuperAdminCount()
	if err != nil {
			log.Panic(err)
			return
Y
Your Name 已提交
47

Y
Your Name 已提交
48 49 50
	}
	if s == 0 {
		if userName == "" {
E
eoLinker API Management 已提交
51 52 53
			log.Fatal("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
			return
		}
Y
Your Name 已提交
54
		if userPassword == "" {
E
eoLinker API Management 已提交
55
			log.Fatal("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
Y
Your Name 已提交
56

E
eoLinker API Management 已提交
57 58 59 60
			return
		}

		// 用户注册
Y
Your Name 已提交
61
		password := utils.Md5(utils.Md5(userPassword))
Y
Your Name 已提交
62
		f := account.Register(userName, password)
E
eoLinker API Management 已提交
63 64 65 66 67
		if !f {
			log.Fatal("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
			return
		}
	}
Y
Your Name 已提交
68 69 70
	Server()
	//console.Router()
	//console.Server()
E
eoLinker API Management 已提交
71
}