chore: add comments to new functions

This commit is contained in:
Juan Pablo Villafáñez
2025-03-18 18:25:01 +01:00
committed by Jörn Friedrich Dreyer
parent 925444a0b3
commit 8b5b3fb430

View File

@@ -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 {