Skip to content

Commit

Permalink
Reduce duplication between New and NewWithContext, per hugelgupf@'s c…
Browse files Browse the repository at this point in the history
…omment.

Signed-off-by: Mark Suter <suter@zwitterion.org>
  • Loading branch information
marksuter committed Jan 8, 2025
1 parent 51ddc3e commit e0b42be
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions dhcpv4/dhcpv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,7 @@ func New(modifiers ...Modifier) (*DHCPv4, error) {
if err != nil {
return nil, err
}
d := DHCPv4{
OpCode: OpcodeBootRequest,
HWType: iana.HWTypeEthernet,
ClientHWAddr: make(net.HardwareAddr, 6),
HopCount: 0,
TransactionID: xid,
NumSeconds: 0,
Flags: 0,
ClientIPAddr: net.IPv4zero,
YourIPAddr: net.IPv4zero,
ServerIPAddr: net.IPv4zero,
GatewayIPAddr: net.IPv4zero,
Options: make(Options),
}
for _, mod := range modifiers {
mod(&d)
}
return &d, nil
return newDHCPv4(xid, modifiers), nil

Check failure on line 149 in dhcpv4/dhcpv4.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.21)

cannot use modifiers (variable of type []Modifier) as Modifier value in argument to newDHCPv4

Check failure on line 149 in dhcpv4/dhcpv4.go

View workflow job for this annotation

GitHub Actions / integration-tests (1.21)

cannot use modifiers (variable of type []Modifier) as Modifier value in argument to newDHCPv4
}

// NewWithContext creates a new DHCPv4 structure and fill it up with default
Expand All @@ -175,6 +158,10 @@ func NewWithContext(ctx context.Context, modifiers ...Modifier) (*DHCPv4, error)
if err != nil {
return nil, err
}
return newDHCPv4(xid, modifiers), nil

Check failure on line 161 in dhcpv4/dhcpv4.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.21)

cannot use modifiers (variable of type []Modifier) as Modifier value in argument to newDHCPv4

Check failure on line 161 in dhcpv4/dhcpv4.go

View workflow job for this annotation

GitHub Actions / integration-tests (1.21)

cannot use modifiers (variable of type []Modifier) as Modifier value in argument to newDHCPv4
}

func newDHCPv4(xid TransactionID, modifiers ...Modifier) *DHCPv4 {
d := DHCPv4{
OpCode: OpcodeBootRequest,
HWType: iana.HWTypeEthernet,
Expand All @@ -192,7 +179,7 @@ func NewWithContext(ctx context.Context, modifiers ...Modifier) (*DHCPv4, error)
for _, mod := range modifiers {
mod(&d)
}
return &d, nil
return &d
}

// NewDiscoveryForInterface builds a new DHCPv4 Discovery message, with a default
Expand Down

0 comments on commit e0b42be

Please sign in to comment.