From 5b5062a35d14d3f0a22b47b20afca1a83eada406 Mon Sep 17 00:00:00 2001 From: siyul-park Date: Wed, 6 Dec 2023 11:45:09 -0500 Subject: [PATCH] refactor: remove http config --- pkg/plugin/networkx/builder.go | 4 +--- pkg/plugin/networkx/builder_test.go | 4 +--- pkg/plugin/networkx/http.go | 11 ++--------- pkg/plugin/networkx/http_test.go | 20 +++++++------------- 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/pkg/plugin/networkx/builder.go b/pkg/plugin/networkx/builder.go index 0c3d4cc5..08af681b 100644 --- a/pkg/plugin/networkx/builder.go +++ b/pkg/plugin/networkx/builder.go @@ -47,9 +47,7 @@ func AddToScheme() func(*scheme.Scheme) error { return func(s *scheme.Scheme) error { s.AddKnownType(KindHTTP, &HTTPSpec{}) s.AddCodec(KindHTTP, scheme.CodecWithType[*HTTPSpec](func(spec *HTTPSpec) (node.Node, error) { - return NewHTTPNode(HTTPNodeConfig{ - Address: spec.Address, - }), nil + return NewHTTPNode(spec.Address), nil })) s.AddKnownType(KindRouter, &RouterSpec{}) diff --git a/pkg/plugin/networkx/builder_test.go b/pkg/plugin/networkx/builder_test.go index 4fb9e077..c9c5ab0c 100644 --- a/pkg/plugin/networkx/builder_test.go +++ b/pkg/plugin/networkx/builder_test.go @@ -19,9 +19,7 @@ func TestAddToHooks(t *testing.T) { port, err := freeport.GetFreePort() assert.NoError(t, err) - n := NewHTTPNode(HTTPNodeConfig{ - Address: fmt.Sprintf(":%d", port), - }) + n := NewHTTPNode(fmt.Sprintf(":%d", port)) err = hk.Load(n) assert.NoError(t, err) diff --git a/pkg/plugin/networkx/http.go b/pkg/plugin/networkx/http.go index 09fe677f..1ebccce7 100644 --- a/pkg/plugin/networkx/http.go +++ b/pkg/plugin/networkx/http.go @@ -22,11 +22,6 @@ import ( "github.com/siyul-park/uniflow/pkg/scheme" ) -// HTTPNodeConfig represents the configuration of an HTTP node. -type HTTPNodeConfig struct { - Address string -} - // HTTPNode represents a node based on the HTTP protocol. type HTTPNode struct { address string @@ -247,10 +242,8 @@ func init() { } } -// NewHTTPNode creates a new HTTPNode with the given configuration. -func NewHTTPNode(config HTTPNodeConfig) *HTTPNode { - address := config.Address - +// NewHTTPNode creates a new HTTPNode. +func NewHTTPNode(address string) *HTTPNode { n := &HTTPNode{ address: address, server: new(http.Server), diff --git a/pkg/plugin/networkx/http_test.go b/pkg/plugin/networkx/http_test.go index 2ea92fd4..d4a70101 100644 --- a/pkg/plugin/networkx/http_test.go +++ b/pkg/plugin/networkx/http_test.go @@ -21,9 +21,7 @@ func TestNewHTTPNode(t *testing.T) { port, err := freeport.GetFreePort() assert.NoError(t, err) - n := NewHTTPNode(HTTPNodeConfig{ - Address: fmt.Sprintf(":%d", port), - }) + n := NewHTTPNode(fmt.Sprintf(":%d", port)) assert.NotNil(t, n) assert.NoError(t, n.Close()) @@ -33,9 +31,7 @@ func TestHTTPNode_Port(t *testing.T) { port, err := freeport.GetFreePort() assert.NoError(t, err) - n := NewHTTPNode(HTTPNodeConfig{ - Address: fmt.Sprintf(":%d", port), - }) + n := NewHTTPNode(fmt.Sprintf(":%d", port)) defer n.Close() p, ok := n.Port(node.PortIO) @@ -59,9 +55,7 @@ func TestHTTPNode_ServeAndShutdown(t *testing.T) { port, err := freeport.GetFreePort() assert.NoError(t, err) - n := NewHTTPNode(HTTPNodeConfig{ - Address: fmt.Sprintf(":%d", port), - }) + n := NewHTTPNode(fmt.Sprintf(":%d", port)) defer n.Close() errChan := make(chan error) @@ -83,7 +77,7 @@ func TestHTTPNode_ServeAndShutdown(t *testing.T) { func TestHTTPNode_ServeHTTP(t *testing.T) { t.Run("IO", func(t *testing.T) { - n := NewHTTPNode(HTTPNodeConfig{}) + n := NewHTTPNode("") defer func() { _ = n.Close() }() io := port.New() @@ -119,7 +113,7 @@ func TestHTTPNode_ServeHTTP(t *testing.T) { }) t.Run("In/Out", func(t *testing.T) { - n := NewHTTPNode(HTTPNodeConfig{}) + n := NewHTTPNode("") defer func() { _ = n.Close() }() in := port.New() @@ -162,7 +156,7 @@ func TestHTTPNode_ServeHTTP(t *testing.T) { func BenchmarkHTTPNode_Send(b *testing.B) { b.Run("IO", func(b *testing.B) { - n := NewHTTPNode(HTTPNodeConfig{}) + n := NewHTTPNode("") defer func() { _ = n.Close() }() io := port.New() @@ -198,7 +192,7 @@ func BenchmarkHTTPNode_Send(b *testing.B) { }) b.Run("In/Out", func(b *testing.B) { - n := NewHTTPNode(HTTPNodeConfig{}) + n := NewHTTPNode("") defer func() { _ = n.Close() }() in := port.New()