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:
@@ -26,7 +26,7 @@ type TCPClient struct {
|
||||
func init() {
|
||||
RegisterModule(ModuleRegistration{
|
||||
Type: "net.tcp.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
|
||||
host, ok := params["host"]
|
||||
|
||||
@@ -75,6 +75,12 @@ func init() {
|
||||
return nil, fmt.Errorf("net.tcp.client unknown framing method: %s", framingMethod)
|
||||
}
|
||||
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
if !ok {
|
||||
return nil, errors.New("net.tcp.client unable to get router from context")
|
||||
}
|
||||
|
||||
return &TCPClient{framer: framer, Addr: addr, config: config, ctx: ctx, router: router, logger: CreateLogger(config)}, nil
|
||||
},
|
||||
})
|
||||
@@ -155,7 +161,7 @@ func (tc *TCPClient) SetupConn() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (tc *TCPClient) Output(payload any) error {
|
||||
func (tc *TCPClient) Output(ctx context.Context, payload any) error {
|
||||
// NOTE(jwetzell): not sure how this would occur but
|
||||
if tc.conn == nil {
|
||||
err := tc.SetupConn()
|
||||
|
||||
Reference in New Issue
Block a user