mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 04:50:14 +09:00
28 lines
551 B
Go
28 lines
551 B
Go
package utils
|
|
|
|
import (
|
|
"database/sql"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/go-redis/redis/v8"
|
|
)
|
|
|
|
func GetDBFromContext(c *gin.Context) *sql.DB {
|
|
return c.MustGet("db").(*sql.DB)
|
|
}
|
|
|
|
func GetCacheFromContext(c *gin.Context) *redis.Client {
|
|
return c.MustGet("cache").(*redis.Client)
|
|
}
|
|
|
|
func GetUserFromContext(c *gin.Context) string {
|
|
return c.MustGet("user").(string)
|
|
}
|
|
|
|
func GetAdminFromContext(c *gin.Context) bool {
|
|
return c.MustGet("admin").(bool)
|
|
}
|
|
|
|
func GetAgentFromContext(c *gin.Context) string {
|
|
return c.MustGet("agent").(string)
|
|
}
|