刷新验证码
This commit is contained in:
53
main.go
53
main.go
@@ -1,5 +1,52 @@
|
||||
package jx_print
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
_ "git.rosy.net.cn/jx-print/controllers"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"git.rosy.net.cn/jx-print/routers"
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-contrib/sessions/cookie"
|
||||
"github.com/gin-gonic/gin"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
gin.DisableConsoleColor()
|
||||
|
||||
r := gin.New()
|
||||
r.Use(session(model.SessionKey))
|
||||
// LoggerWithFormatter middleware will write the logs to gin.DefaultWriter
|
||||
// By default gin.DefaultWriter = os.Stdout
|
||||
r.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
|
||||
|
||||
// your custom format
|
||||
return fmt.Sprintf("%s - [%s] \"%s %s %d \" %s\"\n",
|
||||
param.ClientIP,
|
||||
param.TimeStamp.Format(time.RFC3339),
|
||||
param.Method,
|
||||
param.Path,
|
||||
param.StatusCode,
|
||||
param.ErrorMessage,
|
||||
)
|
||||
}))
|
||||
r.Use(gin.Recovery())
|
||||
routers.Init(r)
|
||||
r.Run()
|
||||
}
|
||||
// 中间件,处理session
|
||||
func session(keyPairs string) gin.HandlerFunc {
|
||||
store := sessionConfig()
|
||||
return sessions.Sessions(keyPairs, store)
|
||||
}
|
||||
func sessionConfig() sessions.Store {
|
||||
sessionMaxAge := 3600
|
||||
sessionSecret := model.SessionKey
|
||||
var store sessions.Store
|
||||
store = cookie.NewStore([]byte(sessionSecret))
|
||||
store.Options(sessions.Options{
|
||||
MaxAge: sessionMaxAge, //seconds
|
||||
Path: "/",
|
||||
})
|
||||
return store
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user