forked from i-love-flamingo/flamingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
templatefunctions.go
49 lines (36 loc) · 855 Bytes
/
templatefunctions.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
44
45
46
47
48
49
package web
import (
"context"
)
type partialDataContextKey string
const ctxKey partialDataContextKey = "partialData"
type SetPartialDataFunc struct{}
func (*SetPartialDataFunc) Func(c context.Context) interface{} {
return func(key string, val interface{}) interface{} {
r, ok := FromContext(c)
if !ok {
return nil
}
data, ok := r.Values.Load(ctxKey)
if !ok || data == nil {
data = make(map[string]interface{})
}
data.(map[string]interface{})[key] = val
r.Values.Store(ctxKey, data)
return nil
}
}
type GetPartialDataFunc struct{}
func (*GetPartialDataFunc) Func(c context.Context) interface{} {
return func() map[string]interface{} {
r, ok := FromContext(c)
if !ok {
return nil
}
data, ok := r.Values.Load(ctxKey)
if !ok || data == nil {
return nil
}
return data.(map[string]interface{})
}
}