From fcbb2bf348ad26df02e801d9db8ce7a7e5517734 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Mon, 28 Aug 2023 11:43:51 -0700 Subject: [PATCH] net/memnet: export the network name (#9111) This makes it more maintainable for other code to statically depend on the exact value of this string. It also makes it easier to identify what code might depend on this string by looking up references to this constant. Updates tailscale/corp#13777 Signed-off-by: Joe Tsai --- net/memnet/conn.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/memnet/conn.go b/net/memnet/conn.go index fb7776e61..a9e1fd399 100644 --- a/net/memnet/conn.go +++ b/net/memnet/conn.go @@ -9,6 +9,10 @@ import ( "time" ) +// NetworkName is the network name returned by [net.Addr.Network] +// for [net.Conn.LocalAddr] and [net.Conn.RemoteAddr] from the [Conn] type. +const NetworkName = "mem" + // Conn is a net.Conn that can additionally have its reads and writes blocked and unblocked. type Conn interface { net.Conn @@ -45,7 +49,7 @@ func NewTCPConn(src, dst netip.AddrPort, maxBuf int) (local Conn, remote Conn) { type connAddr string -func (a connAddr) Network() string { return "mem" } +func (a connAddr) Network() string { return NetworkName } func (a connAddr) String() string { return string(a) } type connHalf struct {