forked from VividCortex/siesta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
41 lines (33 loc) · 990 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
package siesta
// A siesta Context is a context interface that gets passed to each
// contextHandler.
type Context interface {
Set(string, interface{})
Get(string) interface{}
}
// This is a blank context.
type emptyContext struct{}
func (c emptyContext) Set(key string, value interface{}) {
}
func (c emptyContext) Get(key string) interface{} {
return nil
}
// siestaContext is a concrete implementation of the siesta.Context
// interface. Typically this will be created by the siesta framework
// itself upon each request. However creating your own SiestaContext
// might be useful for testing to isolate the behavior of a single
// handler.
type siestaContext struct {
values map[string]interface{}
}
func NewSiestaContext() *siestaContext {
return &siestaContext{
values: make(map[string]interface{}),
}
}
func (c *siestaContext) Set(key string, value interface{}) {
c.values[key] = value
}
func (c *siestaContext) Get(key string) interface{} {
return c.values[key]
}