Defining Pub/Sub interfaces
@@ -27,6 +27,16 @@ type Store interface {
ToLimiterStore(prefix string) (limiter.Store, error)
}
+// Subscriber holds the basic methods to subscribe to a topic
+type Subscriber interface {
+ Subscribe(topic string) *Subscription
+}
+
+// Publisher holds the basic methods to publish a message
+type Publisher interface {
+ Publish(topic string, data []byte) error
+}
+
// Options are options for store.
type Options struct {
// Prefix is the prefix to use for the key.
@@ -39,6 +49,22 @@ type Options struct {
CleanUpInterval time.Duration
}
+// Message represents the message that comes
+// form an update
+type Message []byte
+
+// Subscription holds a message channel
+type Subscription struct {
+ Message chan Message
+}
+
+// NewSubscription creates a new instance of Subscription
+func NewSubscription() *Subscription {
+ return &Subscription{
+ Message: make(chan Message),
+ }
+}
+
// Build creates a new storage based on the provided DSN
func Build(dsn string) (Store, error) {
url, err := url.Parse(dsn)
