1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-18 04:40:03 +02:00
thalos/internal/redis/channel.go

48 lines
799 B
Go

package redis
import (
"strings"
)
// Generic interface for all channel types.
type ChannelInterface interface {
String() string
}
// Standard channel. Just a wrapper around string slice
type Channel []string
func (c *Channel) Append(name ...string) {
*c = append(*c, name...)
}
func (c Channel) String() string {
return strings.Join(c, "/")
}
// Define channels without any variables.
var (
TransactionChannel = Channel{"transaction"}
HeartbeatChannel = Channel{"heartbeat"}
)
// Action channel.
type ActionChannel struct {
Contract string
Action string
}
func (ac ActionChannel) String() string {
ch := Channel{"actions"}
if len(ac.Contract) > 0 {
ch.Append("contract", ac.Contract)
}
if len(ac.Action) > 0 {
ch.Append("action", ac.Action)
}
return ch.String()
}