-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
74 lines (59 loc) · 1.86 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
package main
import (
"fmt"
"github.com/GoAdminGroup/example-temp-gin/pkg/zlog"
"github.com/GoAdminGroup/example-temp-gin/router"
"github.com/sinlovgo/timezone"
"io/ioutil"
"net/http"
"time"
_ "github.com/GoAdminGroup/go-admin/adapter/gin" // adapter
_ "github.com/GoAdminGroup/themes/adminlte" // theme
//_ "github.com/GoAdminGroup/themes/sword" // theme sword
//_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/sqlite" // sqlite driver
_ "github.com/go-sql-driver/mysql" // mysql driver
//_ "github.com/lib/pq" // postgresql driver
configProject "github.com/GoAdminGroup/example-temp-gin/config"
"github.com/GoAdminGroup/go-admin/engine"
"github.com/gin-gonic/gin"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
var (
cfg = pflag.StringP("config", "c", "", "api server config file path.")
)
func main() {
pflag.Parse()
// init config
if err := configProject.Init(*cfg); err != nil {
fmt.Printf("Error, run service not use -c or config yaml error, more info: %v\n", err)
panic(err)
}
fmt.Printf("%s -> %v at time: %v\n", "start service", viper.GetString("name"), time.Now().String())
// set timezone
timezone.SetZoneUTC()
// Set gin mode.
runMode := viper.GetString("run_mode")
gin.SetMode(runMode)
g := gin.Default()
gin.DefaultWriter = ioutil.Discard
eng := engine.Default()
var middlewareList []gin.HandlerFunc
if err := router.Load(
// Cores.
eng, g,
// middlewareList.
middlewareList...,
); err != nil {
zlog.S().Errorf("router.Load error %v", err)
panic(err)
}
zlog.S().Infof("Start to listening the incoming requests on http address: %v", viper.GetString("addr"))
zlog.S().Infof("Sever name: %v , has start!", viper.GetString("name"))
err := http.ListenAndServe(viper.GetString("addr"), g)
if err != nil {
zlog.S().Errorf("server run error %v", err)
} else {
zlog.S().Infof("server run success!")
}
}