看 batch ping 这个库有个写法不理解,代码如下:
//NewBatchPinger returns a new Pinger struct pointer, interval is default 1s, count default 5
func NewBatchPinger(addrs []string, privileged bool) (batachPinger *BatchPinger, err error) {
var network string
if privileged {
network = "ip"
} else {
network = "udp"
}
batachPinger = &BatchPinger{
interval: time.Second,
timeout: time.Second * 100000,
count: 5,
network: network,
id: getPId(),
done: make(chan bool),
addrs: addrs,
mapIpPinger: make(map[string]*Pinger),
mapIpAddr: make(map[string]string),
}
return batachPinger, nil
}
函数里的这个 batachPinger 变量没有定义,为啥可以直接用'=',我自己参考写就报错
1
hdbzsgm 2019-12-23 15:19:19 +08:00
在 return val 里定义
|
2
AzadCypress 2019-12-23 15:23:18 +08:00 via Android
go 命名返回值
你自己搜一下这个 |
3
diagram2048 OP @AzadCypress 明白了,我自己写的名称不一样所以报错,多谢
|