-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
64 lines (53 loc) · 1.09 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
64
package dekaf
import (
"context"
"fmt"
"io"
"sync"
"time"
"github.com/estuary/dekaf/protocol"
)
// Context holds a Kafka request/response pair for processing.
type Context struct {
mu sync.Mutex
conn io.ReadWriter
err error
header *protocol.RequestHeader
parent context.Context
req interface{}
res interface{}
vals map[interface{}]interface{}
}
func (ctx *Context) Request() interface{} {
return ctx.req
}
func (ctx *Context) Response() interface{} {
return ctx.res
}
func (c *Context) Header() *protocol.RequestHeader {
return c.header
}
func (ctx *Context) Deadline() (deadline time.Time, ok bool) {
return time.Time{}, false
}
func (ctx *Context) Done() <-chan struct{} {
return nil
}
func (ctx *Context) Err() error {
return ctx.err
}
func (ctx *Context) String() string {
return fmt.Sprintf("ctx: %s", ctx.header)
}
func (ctx *Context) Value(key interface{}) interface{} {
ctx.mu.Lock()
if ctx.vals == nil {
ctx.vals = make(map[interface{}]interface{})
}
val := ctx.vals[key]
if val == nil {
val = ctx.parent.Value(key)
}
ctx.mu.Unlock()
return val
}