main.go 942 字节
Newer Older
MELF晓宇's avatar
MELF晓宇 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/**
 * @Time    :2021/11/9 15:02
 * @Author  :MELF晓宇
 * @Email   :xyzh.melf@petalmail.com
 * @FileName:main.go
 * @Project :gin-start
 * @Software:GoLand
 * @Blog    :https://blog.csdn.net/qq_29537269
 * @Guide   :https://guide.melf.space
 * @Information:
 *
 */

package main

import (
	"fmt"
MELF晓宇's avatar
MELF晓宇 已提交
18
	"gin-start/config"
19 20
	"gin-start/connection"
	"gin-start/models"
MELF晓宇's avatar
MELF晓宇 已提交
21 22 23 24
	"gin-start/routers"
)

func main() {
MELF晓宇's avatar
MELF晓宇 已提交
25 26 27 28 29 30
	//初始化配置文件
	err := config.InitConfigJson("config\\Config.json")
	if err != nil {
		panic(err)
	}

MELF晓宇's avatar
MELF晓宇 已提交
31
	// 连接数据库
32 33 34 35 36 37 38 39 40
	errPool := connection.InitConnectionPool()
	if errPool != nil {
		panic(errPool)
	}

	// 数据库自动迁移
	errDBCreate := models.DBAutoMigrate()
	if errDBCreate != nil {
		panic(errDBCreate)
MELF晓宇's avatar
MELF晓宇 已提交
41 42
	}

43 44 45
	// 数据表数据初始化
	models.InitModel()

MELF晓宇's avatar
MELF晓宇 已提交
46

MELF晓宇's avatar
MELF晓宇 已提交
47
	// 初始化路由
48 49 50
	r := routers.InitRouter()
	if errRouter := r.Run(); errRouter != nil {
		fmt.Printf("服务启动失败, 异常:%v\n", errRouter)
MELF晓宇's avatar
MELF晓宇 已提交
51 52
	}
}