From fadcf8547f2b679a49344af9182e044476b0cfa4 Mon Sep 17 00:00:00 2001 From: Shahryar Soltanpour Date: Mon, 18 Dec 2023 19:13:57 -0700 Subject: [PATCH] Remove UpdateCacheRequest wrapper struct --- main.go | 3 ++- plugin/plugin.go | 15 ++++++--------- plugin/plugin_test.go | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 739e57d..17c0242 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "github.com/gatewayd-io/gatewayd-plugin-sdk/logging" "github.com/gatewayd-io/gatewayd-plugin-sdk/metrics" p "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin" + v1 "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin/v1" "github.com/getsentry/sentry-go" "github.com/go-redis/redis/v8" "github.com/hashicorp/go-hclog" @@ -56,7 +57,7 @@ func main() { cacheBufferSize = 100 // default value } - pluginInstance.Impl.UpdateCacheChannel = make(chan plugin.UpdateCacheRequest, cacheBufferSize) + pluginInstance.Impl.UpdateCacheChannel = make(chan *v1.Struct, cacheBufferSize) go pluginInstance.Impl.UpdateCache(context.Background()) pluginInstance.Impl.RedisURL = cast.ToString(cfg["redisURL"]) diff --git a/plugin/plugin.go b/plugin/plugin.go index 9bbb43e..57c14ef 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -30,7 +30,7 @@ type Plugin struct { ScanCount int64 ExitOnStartupError bool - UpdateCacheChannel chan UpdateCacheRequest + UpdateCacheChannel chan *v1.Struct // Periodic invalidator configuration. PeriodicInvalidatorEnabled bool @@ -146,18 +146,17 @@ func (p *Plugin) OnTrafficFromClient( return req, nil } -type UpdateCacheRequest struct { - serverResponse *v1.Struct -} +//type UpdateCacheRequest struct { +// serverResponse *v1.Struct +//} func (p *Plugin) UpdateCache(ctx context.Context) { for { - updateCacheRequest, ok := <-p.UpdateCacheChannel + serverResponse, ok := <-p.UpdateCacheChannel if !ok { p.Logger.Info("Channel closed, returning from function") return } - serverResponse := updateCacheRequest.serverResponse OnTrafficFromServerCounter.Inc() resp, err := postgres.HandleServerMessage(serverResponse, p.Logger) @@ -247,9 +246,7 @@ func (p *Plugin) OnTrafficFromServer( _ context.Context, resp *v1.Struct, ) (*v1.Struct, error) { p.Logger.Info("Traffic is coming from the server side") - p.UpdateCacheChannel <- UpdateCacheRequest{ - serverResponse: resp, - } + p.UpdateCacheChannel <- resp return resp, nil } diff --git a/plugin/plugin_test.go b/plugin/plugin_test.go index 229964c..4cefabf 100644 --- a/plugin/plugin_test.go +++ b/plugin/plugin_test.go @@ -44,7 +44,7 @@ func Test_Plugin(t *testing.T) { redisClient := redis.NewClient(redisConfig) assert.NotNil(t, redisClient) - updateCacheChannel := make(chan UpdateCacheRequest, 10) + updateCacheChannel := make(chan *v1.Struct, 10) // Create and initialize a new plugin. logger := hclog.New(&hclog.LoggerOptions{