1 Star 0 Fork 0

wyyyh / qor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
context.go 881 Bytes
一键复制 编辑 原始数据 按行查看 历史
jinzhu 提交于 2017-10-19 10:12 . Refactor qor
package qor
import (
"net/http"
"github.com/jinzhu/gorm"
)
// CurrentUser is an interface, which is used for qor admin to get current logged user
type CurrentUser interface {
DisplayName() string
}
// Context qor context, which is used for many qor components, used to share information between them
type Context struct {
Request *http.Request
Writer http.ResponseWriter
CurrentUser CurrentUser
Roles []string
ResourceID string
DB *gorm.DB
Config *Config
Errors
}
// Clone clone current context
func (context *Context) Clone() *Context {
var clone = *context
return &clone
}
// GetDB get db from current context
func (context *Context) GetDB() *gorm.DB {
if context.DB != nil {
return context.DB
}
return context.Config.DB
}
// SetDB set db into current context
func (context *Context) SetDB(db *gorm.DB) {
context.DB = db
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wyyyh/qor.git
git@gitee.com:wyyyh/qor.git
wyyyh
qor
qor
master

搜索帮助