m/node: add PortString method
This adds the PortString method to Port type as Go very commonly handles
ports as strings. Doing the conversion there avoids littering the
int-to-string conversion all over the place.
Change-Id: I7b077f697be49ac80fd81fd6d78c25080c9d7b75
Reviewed-on: https://review.monogon.dev/c/monogon/+/487
Reviewed-by: Sergiusz Bazanski <serge@monogon.tech>
diff --git a/metropolis/node/ports.go b/metropolis/node/ports.go
index 05cbd9e..e7adfb7 100644
--- a/metropolis/node/ports.go
+++ b/metropolis/node/ports.go
@@ -16,6 +16,8 @@
package node
+import "strconv"
+
// Port is a TCP and/or UDP port number reserved for and used by Metropolis
// node code.
type Port uint16
@@ -57,3 +59,7 @@
}
return "unknown"
}
+
+func (p Port) PortString() string {
+ return strconv.Itoa(int(p))
+}