diff --git a/pkg/node/onetomany.go b/pkg/node/onetomany.go index 10f86539..c63b97fc 100644 --- a/pkg/node/onetomany.go +++ b/pkg/node/onetomany.go @@ -8,11 +8,6 @@ import ( "github.com/siyul-park/uniflow/pkg/process" ) -// OneToManyNodeConfig holds the configuration for OneToManyNode. -type OneToManyNodeConfig struct { - Action func(*process.Process, *packet.Packet) ([]*packet.Packet, *packet.Packet) -} - // OneToManyNode represents a node that processes *packet.Packet with one input and many outputs. type OneToManyNode struct { action func(*process.Process, *packet.Packet) ([]*packet.Packet, *packet.Packet) @@ -25,8 +20,7 @@ type OneToManyNode struct { var _ Node = (*OneToManyNode)(nil) // NewOneToManyNode creates a new OneToManyNode with the given configuration. -func NewOneToManyNode(config OneToManyNodeConfig) *OneToManyNode { - action := config.Action +func NewOneToManyNode(action func(*process.Process, *packet.Packet) ([]*packet.Packet, *packet.Packet)) *OneToManyNode { if action == nil { action = func(_ *process.Process, _ *packet.Packet) ([]*packet.Packet, *packet.Packet) { return nil, nil diff --git a/pkg/node/onetomany_test.go b/pkg/node/onetomany_test.go index 572fe353..d030e9a2 100644 --- a/pkg/node/onetomany_test.go +++ b/pkg/node/onetomany_test.go @@ -14,10 +14,8 @@ import ( ) func TestNewOneToManyNode(t *testing.T) { - n := NewOneToManyNode(OneToManyNodeConfig{ - Action: func(_ *process.Process, inPck *packet.Packet) ([]*packet.Packet, *packet.Packet) { - return []*packet.Packet{inPck}, nil - }, + n := NewOneToManyNode(func(_ *process.Process, inPck *packet.Packet) ([]*packet.Packet, *packet.Packet) { + return []*packet.Packet{inPck}, nil }) assert.NotNil(t, n) @@ -25,10 +23,8 @@ func TestNewOneToManyNode(t *testing.T) { } func TestOneToManyNode_Port(t *testing.T) { - n := NewOneToManyNode(OneToManyNodeConfig{ - Action: func(_ *process.Process, inPck *packet.Packet) ([]*packet.Packet, *packet.Packet) { - return []*packet.Packet{inPck}, nil - }, + n := NewOneToManyNode(func(_ *process.Process, inPck *packet.Packet) ([]*packet.Packet, *packet.Packet) { + return []*packet.Packet{inPck}, nil }) defer func() { _ = n.Close() }() @@ -47,10 +43,8 @@ func TestOneToManyNode_Port(t *testing.T) { func TestOneToManyNode_Send(t *testing.T) { t.Run("return out", func(t *testing.T) { - n := NewOneToManyNode(OneToManyNodeConfig{ - Action: func(_ *process.Process, inPck *packet.Packet) ([]*packet.Packet, *packet.Packet) { - return []*packet.Packet{inPck}, nil - }, + n := NewOneToManyNode(func(_ *process.Process, inPck *packet.Packet) ([]*packet.Packet, *packet.Packet) { + return []*packet.Packet{inPck}, nil }) defer func() { _ = n.Close() }() @@ -92,10 +86,8 @@ func TestOneToManyNode_Send(t *testing.T) { }) t.Run("return err", func(t *testing.T) { - n := NewOneToManyNode(OneToManyNodeConfig{ - Action: func(_ *process.Process, inPck *packet.Packet) ([]*packet.Packet, *packet.Packet) { - return nil, packet.New(primitive.NewString(faker.Word())) - }, + n := NewOneToManyNode(func(_ *process.Process, inPck *packet.Packet) ([]*packet.Packet, *packet.Packet) { + return nil, packet.New(primitive.NewString(faker.Word())) }) defer func() { _ = n.Close() }() @@ -131,10 +123,8 @@ func TestOneToManyNode_Send(t *testing.T) { } func BenchmarkOneToManyNode_Send(b *testing.B) { - n := NewOneToManyNode(OneToManyNodeConfig{ - Action: func(_ *process.Process, inPck *packet.Packet) ([]*packet.Packet, *packet.Packet) { - return []*packet.Packet{inPck}, nil - }, + n := NewOneToManyNode(func(_ *process.Process, inPck *packet.Packet) ([]*packet.Packet, *packet.Packet) { + return []*packet.Packet{inPck}, nil }) defer func() { _ = n.Close() }() diff --git a/pkg/plugin/controllx/switch.go b/pkg/plugin/controllx/switch.go index 0a8fc647..1643ac44 100644 --- a/pkg/plugin/controllx/switch.go +++ b/pkg/plugin/controllx/switch.go @@ -49,9 +49,7 @@ var _ scheme.Spec = (*SwitchSpec)(nil) // NewSwitchNode creates a new SwitchNode with the given configuration. func NewSwitchNode(config SwitchNodeConfig) *SwitchNode { n := &SwitchNode{} - n.OneToManyNode = node.NewOneToManyNode(node.OneToManyNodeConfig{ - Action: n.action, - }) + n.OneToManyNode = node.NewOneToManyNode(n.action) return n } diff --git a/pkg/plugin/networkx/router.go b/pkg/plugin/networkx/router.go index 309f75f8..0d205db5 100644 --- a/pkg/plugin/networkx/router.go +++ b/pkg/plugin/networkx/router.go @@ -78,9 +78,7 @@ func NewRouterNode(config RouterNodeConfig) *RouterNode { methods: map[string]string{}, }, } - n.OneToManyNode = node.NewOneToManyNode(node.OneToManyNodeConfig{ - Action: n.action, - }) + n.OneToManyNode = node.NewOneToManyNode(n.action) return n }