From 8b5b3fb430087bdccfe1c565dbce651ac4c42ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 18 Mar 2025 18:25:01 +0100 Subject: [PATCH] chore: add comments to new functions --- pkg/generators/natsnames.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/generators/natsnames.go b/pkg/generators/natsnames.go index 93cb28f12..54fc15f72 100644 --- a/pkg/generators/natsnames.go +++ b/pkg/generators/natsnames.go @@ -5,6 +5,7 @@ import ( "strconv" ) +// NType is an enum type for the different types of NATS connections type NType int const ( @@ -17,6 +18,8 @@ func (n NType) String() string { return []string{"bus", "kv", "reg"}[n] } +// GenerateConnectionName generates a connection name for a NATS connection +// The connection name will be formatted as follows: "hostname:pid:service:type" func GenerateConnectionName(service string, ntype NType) string { host, err := os.Hostname() if err != nil { @@ -26,6 +29,7 @@ func GenerateConnectionName(service string, ntype NType) string { return firstNRunes(host, 5) + ":" + strconv.Itoa(os.Getpid()) + ":" + service + ":" + ntype.String() } +// firstNRunes returns the first n runes of a string func firstNRunes(s string, n int) string { i := 0 for j := range s {