Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: remove NewNetwork constructor #31

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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