util.go 346 B

123456789101112131415161718
  1. package util
  2. import "net"
  3. // addrToIP attempts to extract a net.IP from a net.Addr
  4. func AddrToIP(addr net.Addr) net.IP {
  5. switch v := addr.(type) {
  6. case *net.TCPAddr:
  7. return v.IP
  8. case *net.UDPAddr:
  9. return v.IP
  10. case *net.IPAddr:
  11. return v.IP
  12. default:
  13. // Handle other potential net.Addr implementations or return nil
  14. return nil
  15. }
  16. }