-
Notifications
You must be signed in to change notification settings - Fork 27
/
events.go
54 lines (47 loc) · 1.18 KB
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package jsm
import (
"fmt"
"github.com/nats-io/jsm.go/api"
"github.com/nats-io/nats-server/v2/server"
)
// ParseEvent parses event e and returns event as for example *api.ConsumerAckMetric, all unknown
// event schemas will be of type *UnknownMessage
func ParseEvent(e []byte) (schema string, event any, err error) {
return api.ParseMessage(e)
}
// ServerKindString takes a kind like server.CLIENT and returns a string describing it
func ServerKindString(kind int) string {
switch kind {
case server.CLIENT:
return "Client"
case server.ROUTER:
return "Router"
case server.GATEWAY:
return "Gateway"
case server.SYSTEM:
return "System"
case server.LEAF:
return "Leafnode"
case server.JETSTREAM:
return "JetStream"
case server.ACCOUNT:
return "Account"
default:
return "Unknown Kind"
}
}
// ServerCidString takes a kind like server.CLIENT a similar cid like the server would, eg cid:10
func ServerCidString(kind int, id uint64) string {
format := "id:%d"
switch kind {
case server.CLIENT:
format = "cid:%d"
case server.ROUTER:
format = "rid:%d"
case server.GATEWAY:
format = "gid:%d"
case server.LEAF:
format = "lid:%d"
}
return fmt.Sprintf(format, id)
}