mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-23 22:29:59 -05:00
chore: add comments to new functions
This commit is contained in:
committed by
Jörn Friedrich Dreyer
parent
925444a0b3
commit
8b5b3fb430
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user