Feat: Dialer interface (why is this not in stdlib)

This commit is contained in:
kayos@tcp.direct 2023-10-28 14:27:34 -07:00
parent f2f4b51076
commit 513277750a
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
2 changed files with 24 additions and 0 deletions

8
ifaces.go Normal file
View File

@ -0,0 +1,8 @@
package common
import "net"
// Dialer is an interface that should exist in stdlib honestly. Make it make sense that it doesn't.
type Dialer interface {
Dial(network, address string) (net.Conn, error)
}

16
ifaces_test.go Normal file
View File

@ -0,0 +1,16 @@
package common
import (
"net"
"testing"
)
func needsDialer(t *testing.T, d any) {
if _, ok := d.(Dialer); !ok {
t.Fatal("d is not a Dialer")
}
}
func TestDialer(t *testing.T) {
needsDialer(t, &net.Dialer{})
}