1
0
mirror of https://github.com/inexio/thola.git synced 2026-10-24 03:08:55 +03:00
Files
thola/internal/network/context.go
2021-09-22 11:45:40 +02:00

33 lines
1.1 KiB
Go

package network
import "context"
type ctxKey byte
const (
requestDeviceConnectionKey ctxKey = iota + 1
snmpGetsInsteadOfWalk
)
// NewContextWithDeviceConnection returns a new context with the device connection
func NewContextWithDeviceConnection(ctx context.Context, con *RequestDeviceConnection) context.Context {
return context.WithValue(ctx, requestDeviceConnectionKey, con)
}
// DeviceConnectionFromContext gets the device connection from the context
func DeviceConnectionFromContext(ctx context.Context) (*RequestDeviceConnection, bool) {
con, ok := ctx.Value(requestDeviceConnectionKey).(*RequestDeviceConnection)
return con, ok
}
// NewContextWithSNMPGetsInsteadOfWalk returns a new context with the request
func NewContextWithSNMPGetsInsteadOfWalk(ctx context.Context, b bool) context.Context {
return context.WithValue(ctx, snmpGetsInsteadOfWalk, b)
}
// SNMPGetsInsteadOfWalkFromContext gets the request from the context
func SNMPGetsInsteadOfWalkFromContext(ctx context.Context) (bool, bool) {
con, ok := ctx.Value(snmpGetsInsteadOfWalk).(bool)
return con, ok
}