forked from itcloudy/gin-base-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (57 loc) · 1.62 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
package main
import (
"flag"
"fmt"
"github.com/gin-gonic/gin"
"github.com/itcloudy/gin-base-framework/common"
"github.com/itcloudy/gin-base-framework/crons"
_ "github.com/itcloudy/gin-base-framework/docs" // docs is generated by Swag CLI, you have to import it.
"github.com/itcloudy/gin-base-framework/router"
"github.com/itcloudy/gin-base-framework/system"
"go.uber.org/zap"
"os"
"path"
)
// @title gin-base-framework Server api
// @version 2.0
// @description gin-base-framework Server api
// @termsOfService https://github.com/itcloudy
func main() {
var err error
fPath, _ := os.Getwd()
fPath = path.Join(fPath, "conf")
configPath := flag.String("c", fPath, "config file path")
flag.Parse()
err = system.LoadConfigInformation(*configPath)
if err != nil {
return
}
go crons.Run()
if common.ServerInfo.Mode == "debug" {
gin.SetMode(gin.DebugMode)
} else if common.ServerInfo.Mode == "release" {
gin.SetMode(gin.ReleaseMode)
}
defer common.Logger.Sync()
//router init
router := router.InitRouter()
server := common.ServerInfo
serverInfo := common.StringsJoin(server.Host, ":", server.Port)
// restart
if server.EnableHttps {
fmt.Println("server start https")
err := router.RunTLS(serverInfo, server.CertFile, server.KeyFile)
fmt.Println(err)
if err != nil {
common.Logger.Error("server start failed ", zap.Error(err))
}
} else {
fmt.Printf("server start info: %s\n", serverInfo)
common.Logger.Info("server start info", zap.String("server", serverInfo))
common.Logger.Sync()
err := router.Run(serverInfo)
if err != nil {
common.Logger.Error("server start failed", zap.Error(err))
}
}
}