struct HostPort
pub struct HostPort {
pub host string
pub port string
}用途
公开结构体 `HostPort`。
参数
hoststring- 主机
portstring- 端口
API
#netIP/端口解析、Unix 上 TCP/UDP IPv4/IPv6 与 Unix 域套接字;Windows TCP 仍有平台限制。
struct HostPortpub struct HostPort {
pub host string
pub port string
}公开结构体 `HostPort`。
host stringport stringnew_host_portpub fn new_host_port() HostPort构造 host port。
无
HostPort — 该类型的值
(HostPort) hostpub fn (hp HostPort) host() string`HostPort` 上的方法:主机。
hp HostPortstring — 结果字符串
(HostPort) portpub fn (hp HostPort) port() string`HostPort` 上的方法:端口。
hp HostPortstring — 结果字符串
ipv4pub fn ipv4(a int, b int, c int, d int) string由四个 0..255 的字节构造 IPv4 地址(长度为 4 的 string)。
a intb intc intd intstring — 结果字符串
parse_ippub fn parse_ip(s &string) string解析为 ip。
s &stringstring — 结果字符串
ip_stringpub fn ip_string(ip &string) stringIP字符串。
ip &stringstring — 结果字符串
ip_is_unspecifiedpub fn ip_is_unspecified(ip &string) bool是否未指定地址。
ip &stringbool — 是否成立
ip_is_loopbackpub fn ip_is_loopback(ip &string) bool是否回环地址。
ip &stringbool — 是否成立
ip_is_privatepub fn ip_is_private(ip &string) bool是否私网地址。
ip &stringbool — 是否成立
join_host_portpub fn join_host_port(host &string, port &string) string拼 host:port。
host &stringport &stringstring — 结果字符串
(&mut HostPort) splitpub fn (hp &mut HostPort) split(hostport string) int`&mut HostPort` 上的方法:按分隔符切开。失败时 throw。
hp &mut HostPorthostport stringint — 该类型的值
struct Connpub struct Conn {
pub network string
pub laddr string
pub raddr string
pub read_deadline_ns int
pub write_deadline_ns int
}公开结构体 `Conn`。
network stringladdr stringraddr stringread_deadline_ns intwrite_deadline_ns intstruct Listenerpub struct Listener {
pub network string
pub addr string
}公开结构体 `Listener`。
network stringaddr stringdialpub fn dial(addr string) int发起连接。
addr stringint — 该类型的值
dial_nspub fn dial_ns(addr string, ns int) int拨号ns。失败时 throw。
addr stringns intint — 该类型的值
listenpub fn listen(addr string) int开始监听。失败时 throw。
addr stringint — 该类型的值
acceptpub fn accept(fd int) int接受一个连接。失败时 throw。
fd intint — 该类型的值
conn_closepub fn conn_close(fd int) int关闭连接。失败时 throw。
fd intint — 该类型的值
conn_writepub fn conn_write(fd int, data &string) int向连接写。失败时 throw。
fd intdata &stringint — 该类型的值
conn_readpub fn conn_read(fd int, max int) string从连接读。失败时 throw。
fd intmax intstring — 结果字符串
(&mut Conn) set_deadlinepub fn (c &mut Conn) set_deadline(t_ns int) int`&mut Conn` 上的方法:设置 deadline。
c &mut Connt_ns intint — 该类型的值
(&mut Conn) set_read_deadlinepub fn (c &mut Conn) set_read_deadline(t_ns int) int`&mut Conn` 上的方法:设置 read deadline。
c &mut Connt_ns intint — 该类型的值
(&mut Conn) set_write_deadlinepub fn (c &mut Conn) set_write_deadline(t_ns int) int`&mut Conn` 上的方法:设置 write deadline。
c &mut Connt_ns intint — 该类型的值
(&Conn) readpub fn (c &Conn) read(max int) string`&Conn` 上的方法:读出最多 max 字节。失败时 throw。
c &Connmax intstring — 结果字符串
(&Conn) writepub fn (c &Conn) write(data &string) int`&Conn` 上的方法:写入数据,返回写入的字节数。失败时 throw。
c &Conndata &stringint — 写入的字节数
(&mut Conn) closepub fn (c &mut Conn) close() int`&mut Conn` 上的方法:关闭资源。失败时 throw。
c &mut Connint — 该类型的值
(Conn) local_addrpub fn (c Conn) local_addr() string`Conn` 上的方法:local地址。
c Connstring — 结果字符串
(Conn) remote_addrpub fn (c Conn) remote_addr() string`Conn` 上的方法:remote地址。
c Connstring — 结果字符串
(Listener) acceptpub fn (l Listener) accept() Conn`Listener` 上的方法:接受一个连接。失败时 throw。
l ListenerConn — 该类型的值
(&mut Listener) closepub fn (l &mut Listener) close() int`&mut Listener` 上的方法:关闭资源。失败时 throw。
l &mut Listenerint — 该类型的值
(Listener) addrpub fn (l Listener) addr() string`Listener` 上的方法:地址。
l Listenerstring — 结果字符串
file_connpub fn file_conn(fd int) Conn从文件描述符构造连接。失败时 throw。
fd intConn — 该类型的值
file_listenerpub fn file_listener(fd int) Listener从文件描述符构造监听器。失败时 throw。
fd intListener — 该类型的值
closed_connpub fn closed_conn() Connclosed连接。
无
Conn — 该类型的值
(&Conn) is_closedpub fn (c &Conn) is_closed() bool`&Conn` 上的方法:判断是否 closed。
c &Connbool — 是否成立
(&Conn) descriptorpub fn (c &Conn) descriptor() int在 `&Conn` 上调用 `descriptor`。失败时 throw。
c &Connint — 该类型的值
struct TCPAddrpub struct TCPAddr {
pub ip string
pub port int
pub zone string
}公开结构体 `TCPAddr`。
ip stringport intzone stringstruct UDPAddrpub struct UDPAddr {
pub ip string
pub port int
pub zone string
}公开结构体 `UDPAddr`。
ip stringport intzone stringstruct IPAddrpub struct IPAddr {
pub ip string
pub zone string
}公开结构体 `IPAddr`。
ip stringzone stringstruct UnixAddrpub struct UnixAddr {
pub name string
pub network string
}公开结构体 `UnixAddr`。
name stringnetwork stringnew_tcp_addrpub fn new_tcp_addr() TCPAddr构造 tcp addr。
无
TCPAddr — 该类型的值
new_udp_addrpub fn new_udp_addr() UDPAddr构造 udp addr。
无
UDPAddr — 该类型的值
new_ip_addrpub fn new_ip_addr() IPAddr构造 ip addr。
无
IPAddr — 该类型的值
new_unix_addrpub fn new_unix_addr() UnixAddr构造 unix addr。
无
UnixAddr — 该类型的值
(TCPAddr) networkpub fn (a TCPAddr) network() string在 `TCPAddr` 上调用 `network`。
a TCPAddrstring — 结果字符串
(UDPAddr) networkpub fn (a UDPAddr) network() string在 `UDPAddr` 上调用 `network`。
a UDPAddrstring — 结果字符串
(IPAddr) networkpub fn (a IPAddr) network() string在 `IPAddr` 上调用 `network`。
a IPAddrstring — 结果字符串
(UnixAddr) networkpub fn (a UnixAddr) network() string在 `UnixAddr` 上调用 `network`。
a UnixAddrstring — 结果字符串
(TCPAddr) to_stringpub fn (a TCPAddr) to_string() string`TCPAddr` 上的方法:转成 string。
a TCPAddrstring — 结果字符串
(&UDPAddr) clonepub fn (a &UDPAddr) clone() UDPAddr`&UDPAddr` 上的方法:拷贝一份独立的 string。
a &UDPAddrUDPAddr — 该类型的值
(UDPAddr) to_stringpub fn (a UDPAddr) to_string() string`UDPAddr` 上的方法:转成 string。
a UDPAddrstring — 结果字符串
(IPAddr) to_stringpub fn (a IPAddr) to_string() string`IPAddr` 上的方法:转成 string。
a IPAddrstring — 结果字符串
(UnixAddr) to_stringpub fn (a UnixAddr) to_string() string`UnixAddr` 上的方法:转成 string。
a UnixAddrstring — 结果字符串
split_host_portpub fn split_host_port(hostport string) HostPort拆 host:port。失败时 throw。
hostport stringHostPort — 该类型的值
resolve_tcp_addrpub fn resolve_tcp_addr(network string, address string) TCPAddr解析 TCP 地址。失败时 throw。
network stringaddress stringTCPAddr — 该类型的值
resolve_udp_addrpub fn resolve_udp_addr(network string, address string) UDPAddr解析 UDP 地址。失败时 throw。
network stringaddress stringUDPAddr — 该类型的值
resolve_ip_addrpub fn resolve_ip_addr(network string, address string) IPAddr解析 IP 地址。失败时 throw。
network stringaddress stringIPAddr — 该类型的值
resolve_unix_addrpub fn resolve_unix_addr(network string, address string) UnixAddr解析 Unix 地址。失败时 throw。
network stringaddress stringUnixAddr — 该类型的值
struct Dialerpub struct Dialer {
pub timeout_ns int
pub dual_stack bool
pub local_ip string
pub local_port int
}公开结构体 `Dialer`。
timeout_ns intdual_stack boollocal_ip stringlocal_port intstruct ListenConfigpub struct ListenConfig {
pub reuse bool
}公开结构体 `ListenConfig`。
reuse boolnew_dialerpub fn new_dialer() Dialer构造 dialer。
无
Dialer — 该类型的值
new_listen_configpub fn new_listen_config() ListenConfig构造 listen config。
无
ListenConfig — 该类型的值
dial_tcppub fn dial_tcp(network string, laddr TCPAddr, raddr TCPAddr) Conn拨 TCP。失败时 throw。
network stringladdr TCPAddrraddr TCPAddrConn — 该类型的值
listen_tcppub fn listen_tcp(network string, laddr TCPAddr) Listener听 TCP。失败时 throw。
network stringladdr TCPAddrListener — 该类型的值
dial_topub fn dial_to(network string, address string) Conn拨到地址。失败时 throw。
network stringaddress stringConn — 该类型的值
listen_onpub fn listen_on(network string, address string) Listener在地址上听。失败时 throw。
network stringaddress stringListener — 该类型的值
dial_contextpub fn dial_context(ctx &context.Context, network string, address string) Conn带上下文拨号。
ctx &context.Contextnetwork stringaddress stringConn — 该类型的值
(Dialer) dialpub fn (d Dialer) dial(network string, address string) Conn`Dialer` 上的方法:发起连接。失败时 throw。
d Dialernetwork stringaddress stringConn — 该类型的值
(Dialer) dial_contextpub fn (d Dialer) dial_context(ctx &context.Context, network string, address string) Conn`Dialer` 上的方法:带上下文拨号。失败时 throw。
d Dialerctx &context.Contextnetwork stringaddress stringConn — 该类型的值
dial_timeoutpub fn dial_timeout(network string, address string, timeout_ns int) Conn带超时拨号。失败时 throw。
network stringaddress stringtimeout_ns intConn — 该类型的值
(ListenConfig) listenpub fn (c ListenConfig) listen(ctx &context.Context, network string, address string) Listener`ListenConfig` 上的方法:开始监听。失败时 throw。
c ListenConfigctx &context.Contextnetwork stringaddress stringListener — 该类型的值
listen_packetpub fn listen_packet(network string, address string) PacketConn听数据报。失败时 throw。
network stringaddress stringPacketConn — 该类型的值
struct Interfacepub struct Interface {
pub index int
pub mtu int
pub name string
pub hardware_addr string
pub flags int
}公开结构体 `Interface`。
index intmtu intname stringhardware_addr stringflags intnew_interfacepub fn new_interface() Interface构造 interface。
无
Interface — 该类型的值
flags_stringpub fn flags_string(f int) stringflags字符串。
f intstring — 结果字符串
(Interface) addrspub fn (ifi Interface) addrs() []string在 `Interface` 上调用 `addrs`。失败时 throw。
ifi Interface[]string — 切片结果
interfacespub fn interfaces() []Interface网卡列表。失败时 throw。
无
[]Interface — 切片结果
interface_addrspub fn interface_addrs() []string网卡地址。失败时 throw。
无
[]string — 切片结果
interface_by_namepub fn interface_by_name(name string) Interface按名取网卡。失败时 throw。
name stringInterface — 该类型的值
interface_by_indexpub fn interface_by_index(index int) Interface按下标取网卡。失败时 throw。
index intInterface — 该类型的值
struct IPNetpub struct IPNet {
pub ip string
pub mask string
}公开结构体 `IPNet`。
ip stringmask stringstruct CIDRpub struct CIDR {
pub ip string
pub ipnet IPNet
}公开结构体 `CIDR`。
ip stringipnet IPNetipv4_zeropub fn ipv4_zero() stringIPv4 全零地址。
无
string — 结果字符串
ipv4_bcastpub fn ipv4_bcast() stringIPv4bcast。
无
string — 结果字符串
ipv4_allsyspub fn ipv4_allsys() stringIPv4allsys。
无
string — 结果字符串
ipv4_allrouterpub fn ipv4_allrouter() stringIPv4allrouter。
无
string — 结果字符串
ipv6_zeropub fn ipv6_zero() stringIPv6全零。
无
string — 结果字符串
ipv6_unspecifiedpub fn ipv6_unspecified() stringIPv6未指定。
无
string — 结果字符串
ipv6_loopbackpub fn ipv6_loopback() stringIPv6回环。
无
string — 结果字符串
ipv6_interface_local_all_nodespub fn ipv6_interface_local_all_nodes() stringIPv6网卡localallnodes。
无
string — 结果字符串
ipv6_link_local_all_nodespub fn ipv6_link_local_all_nodes() stringIPv6linklocalallnodes。
无
string — 结果字符串
ipv6_link_local_all_routerspub fn ipv6_link_local_all_routers() stringIPv6linklocalallrouters。
无
string — 结果字符串
ipv4_maskpub fn ipv4_mask(a int, b int, c int, d int) stringIPv4mask。
a intb intc intd intstring — 结果字符串
cidr_maskpub fn cidr_mask(ones int, bits int) stringcidrmask。
ones intbits intstring — 结果字符串
ip_to4pub fn ip_to4(ip &string) stringIPto4。
ip &stringstring — 结果字符串
ip_to16pub fn ip_to16(ip &string) stringIPto16。
ip &stringstring — 结果字符串
ip_equalpub fn ip_equal(a &string, b &string) boolIP相等。
a &stringb &stringbool — 是否成立
ip_maskpub fn ip_mask(ip &string, mask &string) stringIPmask。
ip &stringmask &stringstring — 结果字符串
ip_default_maskpub fn ip_default_mask(ip &string) stringIPdefaultmask。
ip &stringstring — 结果字符串
ip_mask_sizepub fn ip_mask_size(mask &string) intIPmask尺寸。
mask &stringint — 该类型的值
ip_mask_bitspub fn ip_mask_bits(mask &string) intIPmaskbits。
mask &stringint — 该类型的值
ip_mask_stringpub fn ip_mask_string(mask &string) stringIPmask字符串。
mask &stringstring — 结果字符串
(IPNet) networkpub fn (n IPNet) network() string在 `IPNet` 上调用 `network`。
n IPNetstring — 结果字符串
(IPNet) containspub fn (n IPNet) contains(ip &string) bool`IPNet` 上的方法:判断是否包含给定片段。
n IPNetip &stringbool — 是否成立
(IPNet) to_stringpub fn (n IPNet) to_string() string`IPNet` 上的方法:转成 string。
n IPNetstring — 结果字符串
parse_cidrpub fn parse_cidr(s &string) CIDR解析为 cidr。失败时 throw。
s &stringCIDR — 该类型的值
ip_is_multicastpub fn ip_is_multicast(ip &string) bool判断 ip 是否为 multicast。
ip &stringbool — 是否成立
ip_is_interface_local_multicastpub fn ip_is_interface_local_multicast(ip &string) bool判断 ip 是否为 interface_local_multicast。
ip &stringbool — 是否成立
ip_is_link_local_multicastpub fn ip_is_link_local_multicast(ip &string) bool判断 ip 是否为 link_local_multicast。
ip &stringbool — 是否成立
ip_is_link_local_unicastpub fn ip_is_link_local_unicast(ip &string) bool判断 ip 是否为 link_local_unicast。
ip &stringbool — 是否成立
ip_is_global_unicastpub fn ip_is_global_unicast(ip &string) bool判断 ip 是否为 global_unicast。
ip &stringbool — 是否成立
dial_ippub fn dial_ip(network string, laddr IPAddr, raddr IPAddr) Conn拨号IP。失败时 throw。
network stringladdr IPAddrraddr IPAddrConn — 该类型的值
listen_ippub fn listen_ip(network string, laddr IPAddr) PacketConn监听IP。失败时 throw。
network stringladdr IPAddrPacketConn — 该类型的值
struct MXpub struct MX {
pub host string
pub pref int
}公开结构体 `MX`。
host stringpref intstruct NSpub struct NS {
pub host string
}公开结构体 `NS`。
host stringstruct SRVpub struct SRV {
pub target string
pub port int
pub priority int
pub weight int
}公开结构体 `SRV`。
target stringport intpriority intweight intlookup_hostpub fn lookup_host(host string) []string查找主机。失败时 throw。
host string[]string — 切片结果
lookup_ippub fn lookup_ip(host string) []string查找IP。失败时 throw。
host string[]string — 切片结果
lookup_cnamepub fn lookup_cname(host string) string查找cname。失败时 throw。
host stringstring — 结果字符串
lookup_mxpub fn lookup_mx(name string) []MX查找mx。
name string[]MX — 切片结果
lookup_nspub fn lookup_ns(name string) []NS查找ns。
name string[]NS — 切片结果
lookup_txtpub fn lookup_txt(name string) []string查找txt。
name string[]string — 切片结果
lookup_srvpub fn lookup_srv(service string, proto string, name string) []SRV查找srv。失败时 throw。
service stringproto stringname string[]SRV — 切片结果
lookup_addrpub fn lookup_addr(addr string) []string查找地址。失败时 throw。
addr string[]string — 切片结果
hardware_addr_stringpub fn hardware_addr_string(a &string) stringhardware地址字符串。
a &stringstring — 结果字符串
parse_macpub fn parse_mac(s &string) string解析为 mac。失败时 throw。
s &stringstring — 结果字符串
struct PipeConnpub struct PipeConn {
pub w chan string
pub r chan string
pub closed int
}公开结构体 `PipeConn`。
w chan stringr chan stringclosed intstruct PipePairpub struct PipePair {
pub c1 PipeConn
pub c2 PipeConn
}公开结构体 `PipePair`。
c1 PipeConnc2 PipeConnpipepub fn pipe() PipePairpipe,返回 PipePair。
无
PipePair — 该类型的值
(PipeConn) readpub fn (c PipeConn) read() string`PipeConn` 上的方法:读出最多 max 字节。失败时 throw。
c PipeConnstring — 结果字符串
(PipeConn) writepub fn (c PipeConn) write(data string) int`PipeConn` 上的方法:写入数据,返回写入的字节数。失败时 throw。
c PipeConndata stringint — 写入的字节数
(&mut PipeConn) closepub fn (c &mut PipeConn) close() int`&mut PipeConn` 上的方法:关闭资源。
c &mut PipeConnint — 该类型的值
(PipeConn) local_addrpub fn (c PipeConn) local_addr() string`PipeConn` 上的方法:local地址。
c PipeConnstring — 结果字符串
(PipeConn) remote_addrpub fn (c PipeConn) remote_addr() string`PipeConn` 上的方法:remote地址。
c PipeConnstring — 结果字符串
(PipeConn) networkpub fn (c PipeConn) network() string在 `PipeConn` 上调用 `network`。
c PipeConnstring — 结果字符串
lookup_portpub fn lookup_port(network string, service string) int查找端口。失败时 throw。
network stringservice stringint — 该类型的值
lookup_protocolpub fn lookup_protocol(name string) int查找protocol。失败时 throw。
name stringint — 该类型的值
(&Conn) read_resultpub fn (c &Conn) read_result(n int) io.ReadResult`&Conn` 上的方法:读取结果。
c &Connn intio.ReadResult — 该类型的值
(&Conn) write_resultpub fn (c &Conn) write_result(data string) io.WriteResult`&Conn` 上的方法:写入结果。
c &Conndata stringio.WriteResult — 该类型的值
(&Conn) read_npub fn (c &Conn) read_n(n int) string`&Conn` 上的方法:最多读 n 字节;到末尾可返回更短或空串。失败时 throw。
c &Connn intstring — 结果字符串
(&Conn) write_strpub fn (c &Conn) write_str(data string) int`&Conn` 上的方法:写入字符串。失败时 throw。
c &Conndata stringint — 该类型的值
struct PacketConnpub struct PacketConn {
pub network string
pub laddr string
pub raddr string
}公开结构体 `PacketConn`。
network stringladdr stringraddr stringstruct UDPPacketpub struct UDPPacket {
pub addr UDPAddr
pub data string
}公开结构体 `UDPPacket`。
addr UDPAddrdata string(PacketConn) local_addrpub fn (c PacketConn) local_addr() string`PacketConn` 上的方法:local地址。
c PacketConnstring — 结果字符串
(PacketConn) remote_addrpub fn (c PacketConn) remote_addr() string`PacketConn` 上的方法:remote地址。
c PacketConnstring — 结果字符串
(&PacketConn) readpub fn (c &PacketConn) read(max int) string`&PacketConn` 上的方法:读出最多 max 字节。失败时 throw。
c &PacketConnmax intstring — 结果字符串
(&PacketConn) writepub fn (c &PacketConn) write(data &string) int`&PacketConn` 上的方法:写入数据,返回写入的字节数。失败时 throw。
c &PacketConndata &stringint — 写入的字节数
(PacketConn) read_frompub fn (c PacketConn) read_from(max int) UDPPacket`PacketConn` 上的方法:读取从。失败时 throw。
c PacketConnmax intUDPPacket — 该类型的值
(PacketConn) write_topub fn (c PacketConn) write_to(data &string, addr &UDPAddr) int`PacketConn` 上的方法:写入到。失败时 throw。
c PacketConndata &stringaddr &UDPAddrint — 该类型的值
(&mut PacketConn) closepub fn (c &mut PacketConn) close() int`&mut PacketConn` 上的方法:关闭资源。失败时 throw。
c &mut PacketConnint — 该类型的值
dial_udppub fn dial_udp(network string, laddr UDPAddr, raddr UDPAddr) PacketConn拨号UDP。失败时 throw。
network stringladdr UDPAddrraddr UDPAddrPacketConn — 该类型的值
listen_udppub fn listen_udp(network string, laddr UDPAddr) PacketConn监听UDP。失败时 throw。
network stringladdr UDPAddrPacketConn — 该类型的值
dial_unixpub fn dial_unix(network string, laddr UnixAddr, raddr UnixAddr) Conn拨号Unix 时间。失败时 throw。
network stringladdr UnixAddrraddr UnixAddrConn — 该类型的值
listen_unixpub fn listen_unix(network string, laddr UnixAddr) Listener监听Unix 时间。失败时 throw。
network stringladdr UnixAddrListener — 该类型的值