From b22118898d2dd9cef2af146b52ccac4bd8a290ae Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 13 Jan 2023 13:38:04 +0100 Subject: [PATCH] move channel stuffs from internal/redis to transport. --- main.go | 4 ++-- ship_processor.go | 20 +++++++++---------- {internal/redis => transport}/channel.go | 2 +- {internal/redis => transport}/channel_test.go | 2 +- {internal/redis => transport}/key.go | 2 +- {internal/redis => transport}/key_test.go | 2 +- {internal/redis => transport}/namespace.go | 2 +- .../redis => transport}/namespace_test.go | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) rename {internal/redis => transport}/channel.go (97%) rename {internal/redis => transport}/channel_test.go (98%) rename {internal/redis => transport}/key.go (94%) rename {internal/redis => transport}/key_test.go (98%) rename {internal/redis => transport}/namespace.go (98%) rename {internal/redis => transport}/namespace_test.go (97%) diff --git a/main.go b/main.go index c419317..43aba63 100644 --- a/main.go +++ b/main.go @@ -44,7 +44,7 @@ var abi_mgr *abi.AbiManager var publisher transport.Publisher -var redisNs redis.Namespace +var redisNs transport.Namespace // Reader states const ( @@ -240,7 +240,7 @@ func main() { // Init Abi cache abi_mgr = abi.NewAbiManager(eosClient, conf.Redis.CacheID) - redisNs = redis.Namespace{ + redisNs = transport.Namespace{ Prefix: conf.Redis.Prefix, ChainID: chainInfo.ChainID.String(), } diff --git a/ship_processor.go b/ship_processor.go index aed010a..5073868 100644 --- a/ship_processor.go +++ b/ship_processor.go @@ -6,7 +6,7 @@ import ( log "github.com/sirupsen/logrus" - "eosio-ship-trace-reader/internal/redis" + "eosio-ship-trace-reader/transport" "github.com/eoscanada/eos-go" "github.com/eoscanada/eos-go/ship" ) @@ -34,7 +34,7 @@ func encodeMessage(v interface{}) ([]byte, bool) { return payload, true } -func queueMessage(channel redis.ChannelInterface, payload []byte) bool { +func queueMessage(channel transport.ChannelInterface, payload []byte) bool { key := redisNs.NewKey(channel) err := publisher.Publish(key.String(), payload) if err != nil { @@ -44,7 +44,7 @@ func queueMessage(channel redis.ChannelInterface, payload []byte) bool { return true } -func encodeQueue(channel redis.ChannelInterface, v interface{}) bool { +func encodeQueue(channel transport.ChannelInterface, v interface{}) bool { if payload, ok := encodeMessage(v); ok { if queueMessage(channel, payload) { return true @@ -65,7 +65,7 @@ func processBlock(block *ship.GetBlocksResultV0) { HeadBlockNum: block.Head.BlockNum, } - encodeQueue(redis.HeartbeatChannel, hb) + encodeQueue(transport.HeartbeatChannel, hb) err := publisher.Flush() if err != nil { @@ -77,7 +77,7 @@ func processBlock(block *ship.GetBlocksResultV0) { func processTraces(traces []*ship.TransactionTraceV0) { for _, trace := range traces { - encodeQueue(redis.TransactionChannel, trace) + encodeQueue(transport.TransactionChannel, trace) // Actions for _, actionTraceVar := range trace.ActionTraces { @@ -107,11 +107,11 @@ func processTraces(traces []*ship.TransactionTraceV0) { continue } - channels := []redis.ChannelInterface{ - redis.ActionChannel{}, - redis.ActionChannel{Action: string(act.Action)}, - redis.ActionChannel{Contract: string(act.Contract)}, - redis.ActionChannel{Action: string(act.Action), Contract: string(act.Contract)}, + channels := []transport.ChannelInterface{ + transport.ActionChannel{}, + transport.ActionChannel{Action: string(act.Action)}, + transport.ActionChannel{Contract: string(act.Contract)}, + transport.ActionChannel{Action: string(act.Action), Contract: string(act.Contract)}, } for _, channel := range channels { diff --git a/internal/redis/channel.go b/transport/channel.go similarity index 97% rename from internal/redis/channel.go rename to transport/channel.go index 23d6603..78f0161 100644 --- a/internal/redis/channel.go +++ b/transport/channel.go @@ -1,4 +1,4 @@ -package redis +package transport import ( "strings" diff --git a/internal/redis/channel_test.go b/transport/channel_test.go similarity index 98% rename from internal/redis/channel_test.go rename to transport/channel_test.go index 778b0a4..60cf609 100644 --- a/internal/redis/channel_test.go +++ b/transport/channel_test.go @@ -1,4 +1,4 @@ -package redis +package transport import ( "reflect" diff --git a/internal/redis/key.go b/transport/key.go similarity index 94% rename from internal/redis/key.go rename to transport/key.go index 7e89e68..7c952b9 100644 --- a/internal/redis/key.go +++ b/transport/key.go @@ -1,4 +1,4 @@ -package redis +package transport import ( "fmt" diff --git a/internal/redis/key_test.go b/transport/key_test.go similarity index 98% rename from internal/redis/key_test.go rename to transport/key_test.go index d34a899..5d295a5 100644 --- a/internal/redis/key_test.go +++ b/transport/key_test.go @@ -1,4 +1,4 @@ -package redis +package transport import "testing" diff --git a/internal/redis/namespace.go b/transport/namespace.go similarity index 98% rename from internal/redis/namespace.go rename to transport/namespace.go index 1fbb88d..7352604 100644 --- a/internal/redis/namespace.go +++ b/transport/namespace.go @@ -1,4 +1,4 @@ -package redis +package transport import ( "strings" diff --git a/internal/redis/namespace_test.go b/transport/namespace_test.go similarity index 97% rename from internal/redis/namespace_test.go rename to transport/namespace_test.go index bb52b92..9658c23 100644 --- a/internal/redis/namespace_test.go +++ b/transport/namespace_test.go @@ -1,4 +1,4 @@ -package redis +package transport import "testing"