1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-16 04:24:56 +02:00
thalos/api/channel.go

61 lines
967 B
Go

package api
import (
"strings"
)
// Channel is just a wrapper around string slice
type Channel []string
func (c *Channel) Append(name ...string) {
*c = append(*c, name...)
}
func (c Channel) Format(delimiter string) string {
return strings.Join(c, delimiter)
}
func (c Channel) String() string {
return c.Format("/")
}
// Check if two channels are equal
func (c Channel) Is(other Channel) bool {
if len(c) != len(other) {
return false
}
for i, item := range c {
if item != other[i] {
return false
}
}
return true
}
// Define channels without any variables.
var (
TransactionChannel = Channel{"transaction"}
HeartbeatChannel = Channel{"heartbeat"}
)
// Action Channel
type ActionChannel struct {
Name string
Contract string
}
func (a ActionChannel) Channel() Channel {
ch := Channel{"actions"}
if len(a.Contract) > 0 {
ch.Append("contract", a.Contract)
}
if len(a.Name) > 0 {
ch.Append("name", a.Name)
}
return ch
}