Skip to content

Commit fadcf85

Browse files
committed
Remove UpdateCacheRequest wrapper struct
1 parent 005cf8b commit fadcf85

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/gatewayd-io/gatewayd-plugin-sdk/logging"
99
"github.com/gatewayd-io/gatewayd-plugin-sdk/metrics"
1010
p "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin"
11+
v1 "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin/v1"
1112
"github.com/getsentry/sentry-go"
1213
"github.com/go-redis/redis/v8"
1314
"github.com/hashicorp/go-hclog"
@@ -56,7 +57,7 @@ func main() {
5657
cacheBufferSize = 100 // default value
5758
}
5859

59-
pluginInstance.Impl.UpdateCacheChannel = make(chan plugin.UpdateCacheRequest, cacheBufferSize)
60+
pluginInstance.Impl.UpdateCacheChannel = make(chan *v1.Struct, cacheBufferSize)
6061
go pluginInstance.Impl.UpdateCache(context.Background())
6162

6263
pluginInstance.Impl.RedisURL = cast.ToString(cfg["redisURL"])

plugin/plugin.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Plugin struct {
3030
ScanCount int64
3131
ExitOnStartupError bool
3232

33-
UpdateCacheChannel chan UpdateCacheRequest
33+
UpdateCacheChannel chan *v1.Struct
3434

3535
// Periodic invalidator configuration.
3636
PeriodicInvalidatorEnabled bool
@@ -146,18 +146,17 @@ func (p *Plugin) OnTrafficFromClient(
146146
return req, nil
147147
}
148148

149-
type UpdateCacheRequest struct {
150-
serverResponse *v1.Struct
151-
}
149+
//type UpdateCacheRequest struct {
150+
// serverResponse *v1.Struct
151+
//}
152152

153153
func (p *Plugin) UpdateCache(ctx context.Context) {
154154
for {
155-
updateCacheRequest, ok := <-p.UpdateCacheChannel
155+
serverResponse, ok := <-p.UpdateCacheChannel
156156
if !ok {
157157
p.Logger.Info("Channel closed, returning from function")
158158
return
159159
}
160-
serverResponse := updateCacheRequest.serverResponse
161160

162161
OnTrafficFromServerCounter.Inc()
163162
resp, err := postgres.HandleServerMessage(serverResponse, p.Logger)
@@ -247,9 +246,7 @@ func (p *Plugin) OnTrafficFromServer(
247246
_ context.Context, resp *v1.Struct,
248247
) (*v1.Struct, error) {
249248
p.Logger.Info("Traffic is coming from the server side")
250-
p.UpdateCacheChannel <- UpdateCacheRequest{
251-
serverResponse: resp,
252-
}
249+
p.UpdateCacheChannel <- resp
253250
return resp, nil
254251
}
255252

plugin/plugin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func Test_Plugin(t *testing.T) {
4444
redisClient := redis.NewClient(redisConfig)
4545
assert.NotNil(t, redisClient)
4646

47-
updateCacheChannel := make(chan UpdateCacheRequest, 10)
47+
updateCacheChannel := make(chan *v1.Struct, 10)
4848

4949
// Create and initialize a new plugin.
5050
logger := hclog.New(&hclog.LoggerOptions{

0 commit comments

Comments
 (0)