forked from qor/qor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
43 lines (36 loc) · 881 Bytes
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
}