-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathhandler.go
More file actions
52 lines (41 loc) · 1.32 KB
/
handler.go
File metadata and controls
52 lines (41 loc) · 1.32 KB
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
// Copyright 2018 The agentx authors
// Licensed under the LGPLv3 with static-linking exception.
// See LICENCE file for details.
package agentx
import (
"context"
"github.com/posteo/go-agentx/pdu"
"github.com/posteo/go-agentx/value"
)
// Handler defines an interface for a handler of events that
// might occure during a session.
type Handler interface {
Get(context.Context, value.OID) (value.OID, pdu.VariableType, any, error)
GetNext(context.Context, value.OID, bool, value.OID) (value.OID, pdu.VariableType, any, error)
}
type (
sessionIDKey struct{}
transactionIDKey struct{}
packetIDKey struct{}
)
func SessionID(ctx context.Context) uint32 {
value, _ := ctx.Value(sessionIDKey{}).(uint32)
return value
}
func withSessionID(ctx context.Context, value uint32) context.Context {
return context.WithValue(ctx, sessionIDKey{}, value)
}
func TransactionID(ctx context.Context) uint32 {
value, _ := ctx.Value(transactionIDKey{}).(uint32)
return value
}
func withTransactionID(ctx context.Context, value uint32) context.Context {
return context.WithValue(ctx, transactionIDKey{}, value)
}
func PacketID(ctx context.Context) uint32 {
value, _ := ctx.Value(packetIDKey{}).(uint32)
return value
}
func withPacketID(ctx context.Context, value uint32) context.Context {
return context.WithValue(ctx, packetIDKey{}, value)
}