Documentation ¶
Index ¶
- Constants
- Variables
- func AuthorityAddr(scheme, authority string) (addr string)
- func AuthorityHostPort(scheme, authority string) (host, port string)
- func AuthorityKey(u *url.URL) string
- func ClientIP(r *http.Request) string
- func ClientPublicIP(r *http.Request) string
- func ConnCheck(conn net.Conn) error
- func DiscoverDNS(service, proto string, address string) ([]*net.SRV, error)
- func GetIP(r *http.Request) (string, error)
- func GetLocalIP() string
- func GetPort(addrOrNet interface{}) (int, error)
- func HasLocalIP(ip net.IP) bool
- func HasLocalIPAddr(ip string) bool
- func HasLocalIPddr(ip string) bool
- func HostIP() (string, error)
- func IP2Long(ip net.IP) (uint, error)
- func IPString2Long(ip string) (uint, error)
- func IsPortUsed(protocol string, addr string) bool
- func Listen(address string, opts ...SockOpt) (_ net.Listener, err error)
- func ListenPacket(address string, opts ...SockOpt) (_ net.PacketConn, err error)
- func Long2IP(i uint) (net.IP, error)
- func Long2IPString(i uint) (string, error)
- func MustGetPort(addrOrNet interface{}) int
- func NewTCPSocket(addr string, tlsConfig *tls.Config) (net.Listener, error)
- func RealIP(r *http.Request) string
- func RemoteIP(r *http.Request) string
- func RemoteIp(req *http.Request) string
- type SockOpt
Constants ¶
const ( XForwardedFor = "X-Forwarded-For" XRealIP = "X-Real-IP" )
Variables ¶
var ErrIFNotFound = errors.New("network interface not found")
ErrIFNotFound is returned if we can't find an available network interface.
Functions ¶
func AuthorityAddr ¶ added in v0.2.11
AuthorityAddr returns a given authority (a host/IP, or host:port / ip:port) and returns a host:port. The port 443 is added if needed.
func AuthorityHostPort ¶ added in v0.2.11
func AuthorityKey ¶ added in v0.2.11
func ClientIP ¶ added in v0.2.11
ClientIP 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。
func ClientPublicIP ¶ added in v0.2.11
ClientPublicIP 尽最大努力实现获取客户端公网 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。
func DiscoverDNS ¶
DiscoverDNS ...
func GetLocalIP ¶
func GetLocalIP() string
func HasLocalIP ¶ added in v0.2.11
HasLocalIP 检测 IP 地址是否是内网地址 通过直接对比ip段范围效率更高,详见:https://github.com/thinkeridea/go-extend/issues/2
func HasLocalIPAddr ¶ added in v0.2.11
HasLocalIPAddr 检测 IP 地址字符串是否是内网地址
func HasLocalIPddr ¶ added in v0.2.11
HasLocalIPddr 检测 IP 地址字符串是否是内网地址 Deprecated: 此为一个错误名称错误拼写的函数,计划在将来移除,请使用 HasLocalIPAddr 函数
func HostIP ¶ added in v0.2.11
HostIP tries to return the IPv4 string from the primary network interface.
func IPString2Long ¶ added in v0.2.11
IPString2Long 把ip字符串转为数值
func IsPortUsed ¶ added in v0.2.11
IsPortUsed 检查端口是否被占用
func ListenPacket ¶
func ListenPacket(address string, opts ...SockOpt) (_ net.PacketConn, err error)
func Long2IPString ¶ added in v0.2.11
Long2IPString 把数值转为ip字符串
func MustGetPort ¶
func MustGetPort(addrOrNet interface{}) int
func NewTCPSocket ¶
NewTCPSocket creates a TCP socket listener with the specified address and the specified tls configuration. If tlsConfig is set, will encapsulate the TCP listener inside a TLS one.
Types ¶
type SockOpt ¶
type SockOpt func(opts *sockOpts) error
SockOpt sets up socket file's creating option
func WithNetCfg ¶
func WithNetCfg(fn func(lc *net.ListenConfig)) SockOpt