Documentation ¶
Overview ¶
Package netKit
PS: Golang对于host的定义 不同于 js.
e.g. "127.0.0.1:8888" host in Golang: "127.0.0.1" host in js: "127.0.0.1:8888"
Package netKit *
- 参考:"net"
Index ¶
- Constants
- Variables
- func CanDial(ip string, port int) (bool, error)
- func CanDialWithTimeout(ip string, port int, timeout time.Duration) (bool, error)
- func GetUsablePort(startPort int, exceptivePorts ...int) (int, error)
- func IsLocalPortUsable(port int) (bool, error)
- func IsValidPort(port int) bool
- func JoinHostnameAndPort(hostname string, port int) string
- func ProcessAddresses(addresses []string) ([]string, error)
- type Address
Constants ¶
const (
// MaxPort 65535 == 0xFFFF
MaxPort = 0xFFFF
)
Variables ¶
var (
NoUsablePortError = errorKit.Simple("no usable port")
)
Functions ¶
func GetUsablePort ¶
GetUsablePort 从 传参startPort开始(包括)向后找,返回一个可用的端口,或者直至端口超过上限65535.
@param exceptivePorts 例外的端口(即返回的端口号不在exceptivePorts中)
func IsLocalPortUsable ¶
IsLocalPortUsable 本地端口是否可用(即未被占用)? Deprecated: 某些绑定非127.0.0.1的端口无法被检测到.
PS: 会优先判断端口是否有效(valid).
参考: Java,hutool中的NetUtil.isUsableLocalPort() golang端口占用检测的使用 https://wenku.baidu.com/view/25716f5b01768e9951e79b89680203d8ce2f6af5.html
func IsValidPort ¶
IsValidPort 是否为有效的端口?(根据值范围判断)
参考: Java,hutool中的NetUtil.isValidPort() Linux端口分配: https://blog.csdn.net/zh2508/article/details/104888743
0 不使用 1–1023 系统保留,只能由root用户使用 1024—4999 由客户端程序自由分配 5000—65535 由服务器端程序自由分配(65535 = 2 ^ 16 - 1)
func JoinHostnameAndPort ¶
Types ¶
type Address ¶
func ParseToAddress ¶
ParseToAddress
e.g. ("https://127.0.0.1") => "127.0.0.1:443", nil ("http://127.0.0.1:8888") => "127.0.0.1:8888", nil ("https://blog.csdn.net/weixin_52428496/article/details/110159938") => "blog.csdn.net:443", nil