...

Source file src/github.com/emissary-ingress/emissary/v3/pkg/acp/utils.go

Documentation: github.com/emissary-ingress/emissary/v3/pkg/acp

     1  package acp
     2  
     3  import (
     4  	"net"
     5  )
     6  
     7  // HostPortIsLocal returns true IFF the host:port string from a URL refers to the
     8  // local host. The comparison is simple: if it's "localhost" or "127.0.0.1" or "::1",
     9  // it refers to the local host.
    10  //
    11  // Note that HostPortIsLocal _requires_ the ":port" part, because net.SplitHostPort
    12  // requires it, and because the whole point here is that IPv6 is a pain. Sigh.
    13  func HostPortIsLocal(hostport string) bool {
    14  	// Split out the host part...
    15  	host, _, err := net.SplitHostPort(hostport)
    16  
    17  	// If something went wrong, it ain't local.
    18  	if err != nil {
    19  		// log.Println(fmt.Errorf("HostPortIsLocal: %s got error %v", hostport, err))
    20  		return false
    21  	}
    22  
    23  	return host == "localhost" || host == "127.0.0.1" || host == "::1"
    24  }
    25  

View as plain text