-
Notifications
You must be signed in to change notification settings - Fork 1
/
context.go
63 lines (51 loc) · 1.06 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package core
import (
ctx "context"
"github.com/nicksnyder/go-i18n/v2/i18n"
)
type (
Context interface {
ctx.Context
SetSession(Session)
MustSession() Session
Session() (Session, error)
Localizer() (*i18n.Localizer, error)
MustLocalizer() *i18n.Localizer
SetLocalizer(*i18n.Localizer)
}
context struct {
ctx.Context
session Session
localizer *i18n.Localizer
}
)
func NewContext(ctx ctx.Context, session Session) Context {
return &context{
Context: ctx,
session: session,
}
}
func (c *context) WithContext(ctx ctx.Context) Context {
return &context{
Context: ctx,
session: c.session,
}
}
func (c context) Session() (Session, error) {
return c.session, nil
}
func (c context) MustSession() Session {
return c.session
}
func (c *context) SetSession(session Session) {
c.session = session
}
func (c context) Localizer() (*i18n.Localizer, error) {
return c.localizer, nil
}
func (c context) MustLocalizer() *i18n.Localizer {
return c.localizer
}
func (c *context) SetLocalizer(localizer *i18n.Localizer) {
c.localizer = localizer
}