Skip to content

Commit

Permalink
BREAKING CHANGE: remove NewNetwork constructor (#31)
Browse files Browse the repository at this point in the history
The constructor was just creating the zero value. So remove unneeded
complexity and just tell people to construct and use a zero value
instead. In other words:

- replace `NewNetwork()` with `&Network{}`.
  • Loading branch information
bassosimone authored Nov 25, 2024
1 parent 6f272cb commit db22a4d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions netcore/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestDialerIntegration(t *testing.T) {
}

logger := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{}))
netx := netcore.NewNetwork()
netx := &netcore.Network{}
netx.Logger = logger
netx.WrapConn = netcore.WrapConn

Expand All @@ -39,7 +39,7 @@ func TestTLSDialerIntegration(t *testing.T) {
}

logger := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{}))
netx := netcore.NewNetwork()
netx := &netcore.Network{}
netx.Logger = logger
netx.WrapConn = netcore.WrapConn

Expand Down
9 changes: 2 additions & 7 deletions netcore/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

// Network allows dialing and measuring TCP/UDP/TLS connections.
//
// Construct using [NewNetwork].
// The zero value is ready to use.
//
// A [*Network] is safe for concurrent use by multiple goroutines as long as
// you don't modify its fields after construction and the underlying fields you
Expand Down Expand Up @@ -55,13 +55,8 @@ type Network struct {
WrapConn func(ctx context.Context, netx *Network, conn net.Conn) net.Conn
}

// NewNetwork constructs a new [*Network] with default settings.
func NewNetwork() *Network {
return &Network{}
}

// DefaultNetwork is the default [*Network] used by this package.
var DefaultNetwork = NewNetwork()
var DefaultNetwork = &Network{}

// timeNow is a function that returns the current time.
func (nx *Network) timeNow() time.Time {
Expand Down
2 changes: 1 addition & 1 deletion netsim/netstack/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (ns *Stack) DialContext(ctx context.Context, network, address string) (net.
}

// Configure dnscore and netcore to perform the actual dial.
netx := netcore.NewNetwork()
netx := &netcore.Network{}
netx.DialContextFunc = ns.dialContext
reso := &dnscore.Resolver{}
reso.Config = dnscore.NewConfig()
Expand Down

0 comments on commit db22a4d

Please sign in to comment.