From 513277750a8a45bb9265687c2ddc70bc6df844ee Mon Sep 17 00:00:00 2001 From: "kayos@tcp.direct" Date: Sat, 28 Oct 2023 14:27:34 -0700 Subject: [PATCH] Feat: Dialer interface (why is this not in stdlib) --- ifaces.go | 8 ++++++++ ifaces_test.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 ifaces.go create mode 100644 ifaces_test.go diff --git a/ifaces.go b/ifaces.go new file mode 100644 index 0000000..42f4ddd --- /dev/null +++ b/ifaces.go @@ -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) +} diff --git a/ifaces_test.go b/ifaces_test.go new file mode 100644 index 0000000..a3268f6 --- /dev/null +++ b/ifaces_test.go @@ -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{}) +}