On Wed, Oct 12, 2022 at 09:01:46AM -0700, Christian Worm Mortensen wrote: (I have rehashed the options you've presented, to help commenting on them.)
[...] > 2) I can make a my own struct and return from my custom dialer: > > type myConn struct { > net.Conn > dialInfo string > } > > However, that does not work well for TLS. The reason is that the Go HTTP > client has special logic in case a custom dialer returns a *tls.Conn. That > logic will be disabled. The Conn funtion of the crypto/tls package allows to "upgrade" a user-supplied net.Conn to a tls.Conn, so you could probably try to modify your dialer so that it returns myConn which has, say, LocalAddr method returning a custom type which implements net.Addr but also conveys some information about itself, like in type MyAddr struct { addr net.TCPAddr dialInfo string } ... func (a *MyAddr) DialInfo() string { return m.dialInfo } It's clumsy but should work: you could if laddr, my := someTLSConn.LocalAddr().(*whateverpkg.MyAddr); my { di := laddr.DialInfo() } or type-assert to an interface containing the single DialInfo() method. > 1) I can keep a map from net.Conn to information that identifies the dial. > But when can I delete entries from this map? Go does not have weak pointers. Combined with the idea above, each myConn could keep a reference to the "registry" which maintains the mapping from the conns to the dial information blocks, an have myConn deregister in its Close() method. Alternatively you could use runtime.SetFinalizer() on your custom myConn type - passing it a reference to that "registry" object which had your myConn registered after creation. The type of that registry must be safe for concurrent use in both cases. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20221025114321.exxsktohqjckiyxn%40carbon.