Skip to content

Commit

Permalink
Export the connection interface
Browse files Browse the repository at this point in the history
This way, packages can pass a ConnectionInt implementation around, which
previously was not possible. I.e., previously you had to use
dhcp4client.Connection(&literal{}) directly, now you can use:

    func createClient(conn dhcp4client.ConnectionInt) *dhcp4client.Client {
        return dhcp4client.New(dhcp4client.Connection(conn))
    }
  • Loading branch information
stapelberg committed Jun 2, 2018
1 parent b5d32eb commit e338061
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ type Client struct {
ignoreServers []net.IP //List of Servers to Ignore requests from.
timeout time.Duration //Time before we timeout.
broadcast bool //Set the Bcast flag in BOOTP Flags
connection connection //The Connection Method to use
connection ConnectionInt //The Connection Method to use
generateXID func([]byte) //Function Used to Generate a XID
}

//Abstracts the type of underlying socket used
type connection interface {
type ConnectionInt interface {
Close() error
Write(packet []byte) error
ReadFrom() ([]byte, net.IP, error)
Expand Down Expand Up @@ -90,7 +90,7 @@ func Broadcast(b bool) func(*Client) error {
}
}

func Connection(conn connection) func(*Client) error {
func Connection(conn ConnectionInt) func(*Client) error {
return func(c *Client) error {
c.connection = conn
return nil
Expand Down

0 comments on commit e338061

Please sign in to comment.