forked from f066/api_system_iris
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
62 lines (58 loc) · 1.34 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 (
"api_system_iris/apps"
"api_system_iris/config"
"api_system_iris/utils"
"fmt"
"github.com/kataras/iris"
"github.com/kataras/iris/middleware/logger"
"github.com/kataras/iris/middleware/recover"
"github.com/spf13/viper"
"strings"
)
func newApp() (app *iris.Application) {
app = iris.New()
loglevel := viper.GetString("logLevel")
if len(loglevel) == 0 {
loglevel = "info"
}
app.Logger().SetLevel(loglevel)
c := logger.Config{
Status: true,
IP: true,
Method: true,
Path: true,
Query: true,
Columns: false,
MessageHeaderKeys: []string{"User-Agent"},
}
var excludeExtensions = [...]string{".js", ".css", ".jpg", ".png", ".ico", ".svg",}
c.AddSkipper(func(ctx iris.Context) bool {
path := ctx.Path()
for _,ext := range excludeExtensions {
if strings.HasSuffix(path,ext) {
return true
}
}
return false
})
logger := logger.New(c)
//注册日志记录中间件
app.Use(recover.New())
app.Use(logger)
//注册路由
apps.RegRouter(app,logger)
return
}
func main() {
fmt.Println(utils.GetBuildInfo())
if err := config.Init(""); err != nil {
panic(err)
}
app := newApp()
listenAddr := viper.GetString("listenAddr")
listenPort := viper.GetString("listenPort")
if listenPort == "" {listenPort = "8080"}
addr := listenAddr + ":" + listenPort
app.Run(iris.Addr(addr))
}