1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-08-26 20:18:13 +02:00

transport/channel.go: Rewrite to not use a interface. Action struct has a Channel() method that returns a channel instead.

This commit is contained in:
Henrik Hautakoski 2023-03-07 18:35:58 +01:00
parent 8e99146cc2
commit 68c21c8ed8
9 changed files with 31 additions and 45 deletions

View file

@ -11,7 +11,7 @@ import (
type Key struct {
NS Namespace
Channel transport.ChannelInterface
Channel transport.Channel
}
func (k Key) String() string {

View file

@ -9,7 +9,7 @@ import (
func TestKey_String(t *testing.T) {
type fields struct {
NS Namespace
Channel transport.ChannelInterface
Channel transport.Channel
}
tests := []struct {
name string
@ -19,7 +19,7 @@ func TestKey_String(t *testing.T) {
{"Empty", fields{NS: Namespace{}, Channel: transport.Channel{}}, "ship::0000000000000000000000000000000000000000000000000000000000000000::"},
{"Transactions", fields{NS: Namespace{ChainID: "id"}, Channel: transport.Channel{"transactions"}}, "ship::id::transactions"},
{"Nested", fields{NS: Namespace{ChainID: "id"}, Channel: transport.Channel{"one.two"}}, "ship::id::one.two"},
{"Action", fields{NS: Namespace{ChainID: "id"}, Channel: transport.ActionChannel{Contract: "mycontract"}}, "ship::id::actions/contract/mycontract"},
{"Action", fields{NS: Namespace{ChainID: "id"}, Channel: transport.Action{Contract: "mycontract"}.Channel()}, "ship::id::actions/contract/mycontract"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

View file

@ -27,7 +27,7 @@ type Namespace struct {
}
// Create a new key with this namespace.
func (ns Namespace) NewKey(ch transport.ChannelInterface) Key {
func (ns Namespace) NewKey(ch transport.Channel) Key {
return Key{NS: ns, Channel: ch}
}

View file

@ -22,7 +22,7 @@ func NewPublisher(client *redis.Client, ns Namespace) *Publisher {
}
}
func (r *Publisher) Write(channel transport.ChannelInterface, payload []byte) error {
func (r *Publisher) Write(channel transport.Channel, payload []byte) error {
return r.pipeline.Publish(r.ctx, r.ns.NewKey(channel).String(), payload).Err()
}