mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-24 16:41:35 -04:00
feat: use names for connections to the nats event bus
This commit is contained in:
committed by
Jörn Friedrich Dreyer
parent
df10de7498
commit
ca2dc823ef
38
pkg/generators/natsnames.go
Normal file
38
pkg/generators/natsnames.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user