Documentation ¶
Index ¶
- Constants
- Variables
- func CERT(addr string, cert tls.Certificate, reuseport bool) (net.Listener, error)
- func IsTLS(srv *http.Server) bool
- func LETSENCRYPT(addr string, serverName string, reuseport bool, cacheDirOptional ...string) (net.Listener, error)
- func Listen(network, addr string) (net.Listener, error)
- func ResolveAddr(addr string) string
- func ResolveHostname(addr string) string
- func ResolvePort(addr string) int
- func ResolveScheme(vhost string) string
- func ResolveSchemeFromServer(srv *http.Server) string
- func ResolveURLFromServer(srv *http.Server) string
- func ResolveVHost(addr string) string
- func TCP(addr string, reuseport bool) (net.Listener, error)
- func TCPKeepAlive(addr string, reuseport bool) (ln net.Listener, err error)
- func TLS(addr, certFile, keyFile string, reuseport bool) (net.Listener, error)
- func UNIX(socketFile string, mode os.FileMode) (net.Listener, error)
- type ErrNoReusePort
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 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, serverName string, reuseport bool, 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 can be the server name(domain) or empty if skip verification is the expected behavior (not recommended) and the third 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 Listen ¶ added in v7.3.2
Listen returns TCP listener with SO_REUSEPORT option set.
The returned listener tries enabling the following TCP options, which usually have positive impact on performance:
- TCP_DEFER_ACCEPT. This option expects that the server reads from accepted connections before writing to them.
- TCP_FASTOPEN. See https://lwn.net/Articles/508865/ for details.
Use https://github.com/valyala/tcplisten if you want customizing these options.
Only tcp4 and tcp6 networks are supported.
ErrNoReusePort error is returned if the system doesn't support SO_REUSEPORT.
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 the scheme based on the "vhost"
func ResolveSchemeFromServer ¶
ResolveSchemeFromServer tries to resolve a url scheme based on the server's configuration. Returns "https" on secure server, otherwise "http".
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.
Types ¶
type ErrNoReusePort ¶ added in v7.3.2
type ErrNoReusePort struct {
// contains filtered or unexported fields
}
ErrNoReusePort is returned if the OS doesn't support SO_REUSEPORT.
func (*ErrNoReusePort) Error ¶ added in v7.3.2
func (e *ErrNoReusePort) Error() string
Error implements error interface.