mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-13 09:52:27 +08:00
refactor: eiblog
This commit is contained in:
18
pkg/mid/u.go
Normal file
18
pkg/mid/u.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Package mid provides ...
|
||||
package mid
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gofrs/uuid"
|
||||
)
|
||||
|
||||
// UserMiddleware 用户cookie标记
|
||||
func UserMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
cookie, err := c.Cookie("u")
|
||||
if err != nil || cookie == "" {
|
||||
u1 := uuid.Must(uuid.NewV4()).String()
|
||||
c.SetCookie("u", u1, 86400*730, "/", "", true, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user