mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
stuff values into context
This commit is contained in:
@@ -29,7 +29,7 @@ type SerialClient struct {
|
||||
func init() {
|
||||
RegisterModule(ModuleRegistration{
|
||||
Type: "serial.client",
|
||||
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
||||
New: func(ctx context.Context, config config.ModuleConfig) (Module, error) {
|
||||
params := config.Params
|
||||
port, ok := params["port"]
|
||||
|
||||
@@ -76,6 +76,12 @@ func init() {
|
||||
BaudRate: int(baudRateNum),
|
||||
}
|
||||
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
if !ok {
|
||||
return nil, errors.New("serial.client unable to get router from context")
|
||||
}
|
||||
|
||||
return &SerialClient{config: config, Port: portString, Framer: framer, Mode: &mode, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
|
||||
},
|
||||
})
|
||||
@@ -162,7 +168,7 @@ func (sc *SerialClient) Run() error {
|
||||
}
|
||||
}
|
||||
|
||||
func (sc *SerialClient) Output(payload any) error {
|
||||
func (sc *SerialClient) Output(ctx context.Context, payload any) error {
|
||||
|
||||
payloadBytes, ok := payload.([]byte)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user