mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-19 04:50:02 +02:00
rename transport to api
This commit is contained in:
parent
044ed4e891
commit
102045e47e
15 changed files with 40 additions and 40 deletions
61
api/channel.go
Normal file
61
api/channel.go
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
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 Action struct {
|
||||
Name string
|
||||
Contract string
|
||||
}
|
||||
|
||||
func (a Action) 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue