feat: use names for connections to the nats event bus

This commit is contained in:
Juan Pablo Villafáñez
2025-03-18 11:27:09 +01:00
committed by Jörn Friedrich Dreyer
parent df10de7498
commit ca2dc823ef
18 changed files with 91 additions and 19 deletions

View File

@@ -0,0 +1,38 @@
package generators
import (
"os"
"strconv"
)
type NType int
const (
NTYPE_BUS NType = iota
NTYPE_KEYVALUE
NTYPE_REGISTRY
)
func (n NType) String() string {
return []string{"bus", "kv", "reg"}[n]
}
func GenerateConnectionName(service string, ntype NType) string {
host, err := os.Hostname()
if err != nil {
host = ""
}
return firstNRunes(host, 5) + ":" + strconv.Itoa(os.Getpid()) + ":" + service + ":" + ntype.String()
}
func firstNRunes(s string, n int) string {
i := 0
for j := range s {
if i == n {
return s[:j]
}
i++
}
return s
}