-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcontext.go
43 lines (33 loc) · 1.12 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
package siesta
// Prepending nullByteStr avoids accidental context key collisions.
const nullByteStr = "\x00"
// UsageContextKey is a special context key to get the route usage information
// within a handler.
const UsageContextKey = nullByteStr + "usage"
// Context is a context interface that gets passed to each ContextHandler.
type Context interface {
Set(string, interface{})
Get(string) interface{}
}
// EmptyContext 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 map[string]interface{}
func NewSiestaContext() SiestaContext {
return SiestaContext{}
}
func (c SiestaContext) Set(key string, value interface{}) {
c[key] = value
}
func (c SiestaContext) Get(key string) interface{} {
return c[key]
}