refactor: make Peer.Connections() return a set instead of a slice
This is more flexible since it allows callers to perform efficient lookups on the result.
This commit is contained in:
1 parent
fe4d8b7767
commit
9b9d8a03aa
6 files changed
+16
-9
No files matched your search
+6
-1
@@ -64,13 +64,18 @@ func (routes *Routes) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (peer *Peer) MarshalJSON() ([]byte, error) {
|
||||
conns := peer.Connections()
|
||||
connections := make([]Connection, 0, len(conns))
|
||||
for conn := range conns {
|
||||
connections = append(connections, conn)
|
||||
}
|
||||
return json.Marshal(struct {
|
||||
Name string
|
||||
NickName string
|
||||
UID uint64
|
||||
Version uint64
|
||||
Connections []Connection
|
||||
}{peer.Name.String(), peer.NickName, peer.UID, peer.version, peer.Connections()})
|
||||
}{peer.Name.String(), peer.NickName, peer.UID, peer.version, connections})
|
||||
}
|
||||
|
||||
func (conn *RemoteConnection) MarshalJSON() ([]byte, error) {
|
||||
|
||||
Reference in new issue
Block a user