Skip to content

Commit c809249

Browse files
authored
Merge pull request #22 from arduino/scerza/better-name
Port address label is now formatted in a better way
2 parents 7e8f939 + 2b5c0ae commit c809249

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,19 @@ func toDiscoveryPort(entry *mdns.ServiceEntry) *discovery.Port {
213213
}
214214
}
215215

216+
var name string
217+
if split := strings.Split(entry.Host, "."); len(split) > 0 {
218+
// Use the first part of the entry host name to display
219+
// the address label
220+
name = split[0]
221+
} else {
222+
// Fallback
223+
name = entry.Name
224+
}
225+
216226
return &discovery.Port{
217227
Address: ip,
218-
AddressLabel: fmt.Sprintf("%s at %s", entry.Name, ip),
228+
AddressLabel: fmt.Sprintf("%s at %s", name, ip),
219229
Protocol: "network",
220230
ProtocolLabel: "Network Port",
221231
Properties: props,

0 commit comments

Comments
 (0)