forked from akazwz/gin-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
87 lines (73 loc) · 3.74 KB
/
main.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"database/sql"
"fmt"
"log"
"net/http"
"time"
"github.com/akazwz/go-gin-restful-api/global"
"github.com/akazwz/go-gin-restful-api/initialize"
"github.com/gin-gonic/gin"
)
// @title Golang Restful Api
// @version 1.0
// @description Golang Restful Api Demo
// @termsOfService https://akazwz.com
// @contact.name API Support
// @contact.url https://akazwz.com
// @contact.email akazwz@icloud.com
// @license.name MIT
// @license.url MIT
// @host localhost:8000
// @BasePath /v1
func main() {
//viper初始化配置
global.VP = initialize.InitViper()
if global.VP == nil {
fmt.Println("配置初始化失败")
}
gin.SetMode(global.CFG.Server.Mode)
//gorm初始化数据库
global.GDB = initialize.InitDB()
if global.GDB != nil {
initialize.CreateTables(global.GDB)
db, _ := global.GDB.DB()
defer func(db *sql.DB) {
err := db.Close()
if err != nil {
}
}(db)
} else {
fmt.Println("数据库连接失败")
return
}
global.GRDB = initialize.InitRDB()
if global.GRDB == nil {
log.Println("Redis数据库连接失败")
return
}
time.Sleep(10 * time.Microsecond)
str := `
██████╗ ██████╗ ██████╗ ██╗███╗ ██╗ ██████╗ ███████╗███████╗████████╗███████╗██╗ ██╗██╗ █████╗ ██████╗ ██╗
██╔════╝ ██╔═══██╗ ██╔════╝ ██║████╗ ██║ ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔════╝██║ ██║██║ ██╔══██╗██╔══██╗██║
██║ ███╗██║ ██║█████╗██║ ███╗██║██╔██╗ ██║█████╗██████╔╝█████╗ ███████╗ ██║ █████╗ ██║ ██║██║█████╗███████║██████╔╝██║
██║ ██║██║ ██║╚════╝██║ ██║██║██║╚██╗██║╚════╝██╔══██╗██╔══╝ ╚════██║ ██║ ██╔══╝ ██║ ██║██║╚════╝██╔══██║██╔═══╝ ██║
╚██████╔╝╚██████╔╝ ╚██████╔╝██║██║ ╚████║ ██║ ██║███████╗███████║ ██║ ██║ ╚██████╔╝███████╗ ██║ ██║██║ ██║
╚═════╝ ╚═════╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
`
fmt.Println(str)
routers := initialize.Routers()
addr := fmt.Sprintf(":%d", global.CFG.Server.Addr)
ReadTimeout := global.CFG.Server.ReadTimeout
WriteTimeout := global.CFG.Server.WriteTimeout
s := &http.Server{
Addr: addr,
Handler: routers,
ReadTimeout: ReadTimeout * time.Second,
WriteTimeout: WriteTimeout * time.Second,
MaxHeaderBytes: 1 << 20,
}
if err := s.ListenAndServe(); err != nil {
fmt.Println(`System Serve Start Error`)
}
}