Documentation ¶
Index ¶
- Constants
- Variables
- func CERT(addr string, cert tls.Certificate) (net.Listener, error)
- func Client(timeout time.Duration) *http.Client
- func GetIPAddress(ipAddresses []string, privateRanges []IPRange) (string, bool)
- func IPInRange(r IPRange, ipAddress net.IP) bool
- func IPIsPrivateSubnet(ipAddress net.IP, privateRanges []IPRange) bool
- func IsTLS(srv *http.Server) bool
- func LETSENCRYPT(addr string, reuse bool, serverName string, cacheDirOptional ...string) (net.Listener, error)
- func ResolveAddr(addr string) string
- func ResolveHostname(addr string) string
- func ResolvePort(addr string) int
- func ResolveScheme(isTLS bool) string
- func ResolveSchemeFromServer(srv *http.Server) string
- func ResolveSchemeFromVHost(vhost string) string
- func ResolveURL(scheme string, addr string) string
- func ResolveURLFromServer(srv *http.Server) string
- func ResolveVHost(addr string) string
- func TCP(addr string, reuse bool) (net.Listener, error)
- func TCPKeepAlive(addr string, reuse bool) (ln net.Listener, err error)
- func TLS(addr, certFile, keyFile string) (net.Listener, error)
- func UNIX(socketFile string, mode os.FileMode) (net.Listener, error)
- type IPRange
Constants ¶
const ( // SchemeHTTPS the "https" url scheme. SchemeHTTPS = "https" // SchemeHTTP the "http" url scheme. SchemeHTTP = "http" )
Variables ¶
var IsLoopbackHost = func(requestHost string) bool { portOrPathIdx := strings.LastIndexByte(requestHost, ':') if portOrPathIdx == 0 { return true } if portOrPathIdx == -1 { portOrPathIdx = strings.LastIndexByte(requestHost, '/') if portOrPathIdx == -1 { portOrPathIdx = len(requestHost) } } subdomainFinishIdx := strings.IndexByte(requestHost, '.') + 1 if l := len(requestHost); l <= subdomainFinishIdx || l < portOrPathIdx { return false } hostname := requestHost[subdomainFinishIdx:portOrPathIdx] if hostname == "" { return false } valid := loopbackRegex.MatchString(hostname) if !valid { valid = hostname == machineHostname } return valid }
IsLoopbackHost tries to catch the local addresses when a developer navigates to a subdomain that its hostname differs from Application.Config.Addr. Developer may want to override this function to return always false in order to not allow different hostname from Application.Config.Addr in local environment (remote is not reached).
var IsLoopbackSubdomain = func(s string) bool { if strings.HasPrefix(s, "127.0.0.1:") || s == "127.0.0.1" { return true } valid := loopbackSubRegex.MatchString(s) if !valid { if !strings.Contains(machineHostname, ".") { valid = s == machineHostname } } return valid }
IsLoopbackSubdomain checks if a string is a subdomain or a hostname.
Functions ¶
func CERT ¶
CERT returns a listener which contans tls.Config with the provided certificate, use for ssl.
func GetIPAddress ¶
GetIPAddress returns a valid public IP Address from a collection of IP Addresses and a range of private subnets.
Reports whether a valid IP was found.
func IPIsPrivateSubnet ¶
IPIsPrivateSubnet reports whether this "ipAddress" is in a private subnet.
func IsTLS ¶
IsTLS returns true if the "srv" contains any certificates or a get certificate function, meaning that is secure.
func LETSENCRYPT ¶
func LETSENCRYPT(addr string, reuse bool, serverName string, cacheDirOptional ...string) (net.Listener, error)
LETSENCRYPT returns a new Automatic TLS Listener using letsencrypt.org service receives three parameters, the first is the host of the server, second one should declare if the underline tcp listener can be binded more than once, third can be the server name(domain) or empty if skip verification is the expected behavior (not recommended), and the forth is optionally, the cache directory, if you skip it then the cache directory is "./certcache" if you want to disable cache directory then simple give it a value of empty string ""
does NOT supports localhost domains for testing.
this is the recommended function to use when you're ready for production state.
func ResolveAddr ¶
ResolveAddr tries to convert a given string to an address which is compatible with net.Listener and server
func ResolveHostname ¶
ResolveHostname receives an addr of form host[:port] and returns the hostname part of it ex: localhost:8080 will return the `localhost`, mydomain.com:8080 will return the 'mydomain'
func ResolvePort ¶
ResolvePort receives an addr of form host[:port] and returns the port part of it ex: localhost:8080 will return the `8080`, mydomain.com will return the '80'
func ResolveScheme ¶
ResolveScheme returns "https" if "isTLS" receiver is true, otherwise "http".
func ResolveSchemeFromServer ¶
ResolveSchemeFromServer tries to resolve a url scheme based on the server's configuration. Returns "https" on secure server, otherwise "http".
func ResolveSchemeFromVHost ¶
ResolveSchemeFromVHost returns the scheme based on the "vhost".
func ResolveURL ¶
ResolveURL takes the scheme and an address and returns its URL, pure implementation but it does the job.
func ResolveURLFromServer ¶
ResolveURLFromServer returns the scheme+host from a server.
func ResolveVHost ¶
ResolveVHost tries to get the hostname if port is no needed for Addr's usage. Addr is being used inside router->subdomains and inside {{ url }} template funcs. It should be the same as "browser's" usually they removing :80 or :443.
func TCPKeepAlive ¶
TCPKeepAlive returns a new tcp keep alive Listener and an error on failure.