User list
This commit is contained in:
45
app/main.go
45
app/main.go
@ -3,9 +3,11 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"iris-test/app/views"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/middleware/accesslog"
|
||||
"github.com/kataras/iris/v12/sessions"
|
||||
"github.com/kataras/iris/v12/sessions/sessiondb/redis"
|
||||
)
|
||||
@ -41,10 +43,49 @@ func createSessionEngine() *sessions.Sessions {
|
||||
return sessions_engine
|
||||
}
|
||||
|
||||
func createAccessLog() *accesslog.AccessLog {
|
||||
// Initialize a new access log middleware.
|
||||
ac := accesslog.New(os.Stdout)
|
||||
// Remove this line to disable logging to console:
|
||||
// ac.AddOutput(os.Stdout)
|
||||
|
||||
// The default configuration:
|
||||
ac.Delim = '|'
|
||||
ac.TimeFormat = "2006-01-02 15:04:05"
|
||||
ac.Async = false
|
||||
ac.IP = true
|
||||
ac.BytesReceivedBody = true
|
||||
ac.BytesSentBody = true
|
||||
ac.BytesReceived = false
|
||||
ac.BytesSent = false
|
||||
ac.BodyMinify = true
|
||||
ac.RequestBody = true
|
||||
ac.ResponseBody = false
|
||||
ac.KeepMultiLineError = true
|
||||
ac.PanicLog = accesslog.LogHandler
|
||||
|
||||
// Default line format if formatter is missing:
|
||||
// Time|Latency|Code|Method|Path|IP|Path Params Query Fields|Bytes Received|Bytes Sent|Request|Response|
|
||||
//
|
||||
// Set Custom Formatter:
|
||||
ac.SetFormatter(&accesslog.JSON{
|
||||
Indent: " ",
|
||||
HumanTime: true,
|
||||
})
|
||||
// ac.SetFormatter(&accesslog.CSV{})
|
||||
// ac.SetFormatter(&accesslog.Template{Text: "{{.Code}}"})
|
||||
|
||||
return ac
|
||||
}
|
||||
|
||||
func createApp() *iris.Application {
|
||||
sessions_engine := createSessionEngine()
|
||||
sessionsEngine := createSessionEngine()
|
||||
accessLog := createAccessLog()
|
||||
|
||||
app := iris.New()
|
||||
app.Use(sessions_engine.Handler())
|
||||
app.Logger().SetLevel(Config.Application.LogLevel)
|
||||
app.Use(sessionsEngine.Handler())
|
||||
app.UseRouter(accessLog.Handler)
|
||||
app.RegisterView(iris.Jet("./app/templates", ".jet").Reload(true))
|
||||
views.CreateRouter(app)
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user