generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
subscriber_key.go
34 lines (27 loc) · 897 Bytes
/
subscriber_key.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
package model
import (
"errors"
)
type SubscriberKey = KeyType[SubscriberPayload, *SubscriberPayload]
func NewSubscriberKey(module, subscription, sink string) SubscriberKey {
return newKey[SubscriberPayload](module, subscription)
}
func ParseSubscriberKey(key string) (SubscriberKey, error) {
return parseKey[SubscriberPayload](key)
}
type SubscriberPayload struct {
Module string
Subscription string
}
var _ KeyPayload = (*SubscriberPayload)(nil)
func (s *SubscriberPayload) Kind() string { return "subr" }
func (s *SubscriberPayload) String() string { return s.Module + "-" + s.Subscription }
func (s *SubscriberPayload) Parse(parts []string) error {
if len(parts) != 2 {
return errors.New("expected <module>-<subscription> but got empty string")
}
s.Module = parts[0]
s.Subscription = parts[1]
return nil
}
func (s *SubscriberPayload) RandomBytes() int { return 10 }