mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2026-05-08 06:52:10 +08:00
29 lines
575 B
Go
29 lines
575 B
Go
package user
|
|
|
|
import (
|
|
"github.com/0xJacky/Nginx-UI/model"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/uozi-tech/cosy"
|
|
)
|
|
|
|
// GetInitUser get the init user from database with caching
|
|
func GetInitUser(c *gin.Context) *model.User {
|
|
const initUserID = 1
|
|
// Try to get from cache first
|
|
if cachedUser, found := GetCachedUser(initUserID); found {
|
|
return cachedUser
|
|
}
|
|
|
|
// If not in cache, get from database
|
|
db := cosy.UseDB(c)
|
|
user := &model.User{}
|
|
db.First(user, initUserID)
|
|
|
|
// Cache the user for future requests
|
|
if user.ID != 0 {
|
|
CacheUser(user)
|
|
}
|
|
|
|
return user
|
|
}
|