-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.go
More file actions
46 lines (36 loc) · 797 Bytes
/
context.go
File metadata and controls
46 lines (36 loc) · 797 Bytes
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
package broc
import (
"errors"
"github.com/nats-io/nats.go"
)
type Context struct {
broc *Broc
msg *nats.Msg
handlers []Handler
meta map[string]interface{}
current int
}
func NewContext(broc *Broc) *Context {
return &Context{
broc: broc,
meta: make(map[string]interface{}),
current: 0,
}
}
func (ctx *Context) Set(propName string, value interface{}) {
ctx.meta[propName] = value
}
func (ctx *Context) Get(propName string) interface{} {
value, _ := ctx.meta[propName]
return value
}
func (ctx *Context) GetMeta() map[string]interface{} {
return ctx.meta
}
func (ctx *Context) Next() (interface{}, error) {
ctx.current++
if ctx.current == len(ctx.handlers) {
return nil, errors.New("no more handlers")
}
return ctx.handlers[ctx.current](ctx)
}