Don't write ipv6 peers field if empty

This commit is contained in:
Justin Li 2014-07-23 00:56:11 -04:00
parent b99e5e0c36
commit e7481b31c1

View file

@ -40,7 +40,12 @@ func (w *Writer) WriteAnnounce(res *models.AnnounceResponse) error {
dict["peers"] = compactPeers(false, res.IPv4Peers) dict["peers"] = compactPeers(false, res.IPv4Peers)
} }
if res.IPv6Peers != nil { if res.IPv6Peers != nil {
dict["peers6"] = compactPeers(true, res.IPv6Peers) compact := compactPeers(true, res.IPv6Peers)
// Don't bother writing the IPv6 field if there is no value.
if len(compact) > 0 {
dict["peers6"] = compact
}
} }
} else if res.IPv4Peers != nil || res.IPv6Peers != nil { } else if res.IPv4Peers != nil || res.IPv6Peers != nil {
dict["peers"] = peersList(res.IPv6Peers, res.IPv4Peers) dict["peers"] = peersList(res.IPv6Peers, res.IPv4Peers)