code: func HostPortToIP(hostport string, ctx *net.TCPAddr) (hostaddr *net.TCPAddr, err error) {
  	host, port, err := net.SplitHostPort(hostport)
  	if err != nil {
  		return nil, err
  	}
  	iport, err := strconv.Atoi(port)
  	if err != nil || iport < 0 || iport > 0xFFFF {
  		return nil, fmt.Errorf("invalid port %d", iport)
  	}
  	var addr net.IP
  	if ctx != nil && host == "localhost" {
  		if ctx.IP.To4() != nil {
  			addr = net.IPv4(127, 0, 0, 1)
  		} else {
  			addr = net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
  		}
  	} else if addr = net.ParseIP(host); addr == nil {
  		return nil, fmt.Errorf("could not parse IP %s", host)
  	}
  
  	return &net.TCPAddr{IP: addr, Port: iport}, nil
  }
docs: // HostPortToIP parses a host:port to a TCPAddr without resolving names.
  // If given a context IP, it will resolve localhost to match the context's IP family.