Skip to content

Commit 1cccc46

Browse files
authored
Merge pull request #60 from gatewayd-io/json-binary
Implement the new JSON binary protocol
2 parents 7941b93 + 6151821 commit 1cccc46

File tree

4 files changed

+82
-71
lines changed

4 files changed

+82
-71
lines changed

go.mod

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ module github.com/gatewayd-io/gatewayd-plugin-cache
33
go 1.20
44

55
require (
6-
github.com/alicebob/miniredis/v2 v2.30.1
7-
github.com/gatewayd-io/gatewayd-plugin-sdk v0.1.0
8-
github.com/getsentry/sentry-go v0.22.0
9-
github.com/go-co-op/gocron v1.30.1
6+
github.com/alicebob/miniredis/v2 v2.30.5
7+
github.com/gatewayd-io/gatewayd-plugin-sdk v0.1.1
8+
github.com/getsentry/sentry-go v0.23.0
9+
github.com/go-co-op/gocron v1.33.1
1010
github.com/go-redis/redis/v8 v8.11.5
1111
github.com/hashicorp/go-hclog v1.5.0
12-
github.com/hashicorp/go-plugin v1.4.10
13-
github.com/jackc/pgx/v5 v5.4.1
12+
github.com/hashicorp/go-plugin v1.5.0
13+
github.com/jackc/pgx/v5 v5.4.3
1414
github.com/prometheus/client_golang v1.16.0
1515
github.com/spf13/cast v1.5.1
16-
github.com/stretchr/testify v1.8.2
16+
github.com/stretchr/testify v1.8.4
1717
github.com/zenizh/go-capturer v0.0.0-20211219060012-52ea6c8fed04
18-
google.golang.org/grpc v1.56.2
19-
google.golang.org/protobuf v1.31.0
18+
google.golang.org/grpc v1.57.0
2019
)
2120

2221
require (
@@ -27,6 +26,7 @@ require (
2726
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
2827
github.com/fatih/color v1.15.0 // indirect
2928
github.com/golang/protobuf v1.5.3 // indirect
29+
github.com/google/uuid v1.3.1 // indirect
3030
github.com/hashicorp/yamux v0.1.1 // indirect
3131
github.com/mattn/go-colorable v0.1.13 // indirect
3232
github.com/mattn/go-isatty v0.0.19 // indirect
@@ -37,13 +37,14 @@ require (
3737
github.com/pmezard/go-difflib v1.0.0 // indirect
3838
github.com/prometheus/client_model v0.4.0 // indirect
3939
github.com/prometheus/common v0.44.0 // indirect
40-
github.com/prometheus/procfs v0.11.0 // indirect
40+
github.com/prometheus/procfs v0.11.1 // indirect
4141
github.com/robfig/cron/v3 v3.0.1 // indirect
4242
github.com/yuin/gopher-lua v1.1.0 // indirect
4343
go.uber.org/atomic v1.11.0 // indirect
44-
golang.org/x/net v0.12.0 // indirect
45-
golang.org/x/sys v0.10.0 // indirect
46-
golang.org/x/text v0.11.0 // indirect
47-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect
44+
golang.org/x/net v0.14.0 // indirect
45+
golang.org/x/sys v0.12.0 // indirect
46+
golang.org/x/text v0.13.0 // indirect
47+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
48+
google.golang.org/protobuf v1.31.0 // indirect
4849
gopkg.in/yaml.v3 v3.0.1 // indirect
4950
)

go.sum

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk=
22
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
3-
github.com/alicebob/miniredis/v2 v2.30.1 h1:HM1rlQjq1bm9yQcsawJqSZBJ9AYgxvjkMsNtddh90+g=
4-
github.com/alicebob/miniredis/v2 v2.30.1/go.mod h1:b25qWj4fCEsBeAAR2mlb0ufImGC6uH3VlUfb/HS5zKg=
3+
github.com/alicebob/miniredis/v2 v2.30.5 h1:3r6kTHdKnuP4fkS8k2IrvSfxpxUTcW1SOL0wN7b7Dt0=
4+
github.com/alicebob/miniredis/v2 v2.30.5/go.mod h1:b25qWj4fCEsBeAAR2mlb0ufImGC6uH3VlUfb/HS5zKg=
55
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
66
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
7+
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
78
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
89
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
910
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
@@ -20,12 +21,12 @@ github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
2021
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
2122
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
2223
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
23-
github.com/gatewayd-io/gatewayd-plugin-sdk v0.1.0 h1:KLxUoh063oMsQmGNsT+Txmyi4M1O673oZbdsk5l1ENs=
24-
github.com/gatewayd-io/gatewayd-plugin-sdk v0.1.0/go.mod h1:B4oWVHf7NeSCs7szN8nrlIO6tkznV1F3ZMqE9VxDtKY=
25-
github.com/getsentry/sentry-go v0.22.0 h1:XNX9zKbv7baSEI65l+H1GEJgSeIC1c7EN5kluWaP6dM=
26-
github.com/getsentry/sentry-go v0.22.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
27-
github.com/go-co-op/gocron v1.30.1 h1:tjWUvJl5KrcwpkEkSXFSQFr4F9h5SfV/m4+RX0cV2fs=
28-
github.com/go-co-op/gocron v1.30.1/go.mod h1:39f6KNSGVOU1LO/ZOoZfcSxwlsJDQOKSu8erN0SH48Y=
24+
github.com/gatewayd-io/gatewayd-plugin-sdk v0.1.1 h1:ujlh6TSDFmG2e9VtY6hZk8BW0p7i0AEQL3BpMMLzxwc=
25+
github.com/gatewayd-io/gatewayd-plugin-sdk v0.1.1/go.mod h1:B4oWVHf7NeSCs7szN8nrlIO6tkznV1F3ZMqE9VxDtKY=
26+
github.com/getsentry/sentry-go v0.23.0 h1:dn+QRCeJv4pPt9OjVXiMcGIBIefaTJPw/h0bZWO05nE=
27+
github.com/getsentry/sentry-go v0.23.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
28+
github.com/go-co-op/gocron v1.33.1 h1:wjX+Dg6Ae29a/f9BSQjY1Rl+jflTpW9aDyMqseCj78c=
29+
github.com/go-co-op/gocron v1.33.1/go.mod h1:NLi+bkm4rRSy1F8U7iacZOz0xPseMoIOnvabGoSe/no=
2930
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
3031
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
3132
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
@@ -45,17 +46,19 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
4546
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
4647
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
4748
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
49+
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
50+
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
4851
github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c=
4952
github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
50-
github.com/hashicorp/go-plugin v1.4.10 h1:xUbmA4jC6Dq163/fWcp8P3JuHilrHHMLNRxzGQJ9hNk=
51-
github.com/hashicorp/go-plugin v1.4.10/go.mod h1:6/1TEzT0eQznvI/gV2CM29DLSkAK/e58mUWKVsPaph0=
53+
github.com/hashicorp/go-plugin v1.5.0 h1:g6Lj3USwF5LaB8HlvCxPjN2X4nFE08ko2BJNVpl7TIE=
54+
github.com/hashicorp/go-plugin v1.5.0/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4=
5255
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
5356
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
5457
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
5558
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
56-
github.com/jackc/pgx/v5 v5.4.1 h1:oKfB/FhuVtit1bBM3zNRRsZ925ZkMN3HXL+LgLUM9lE=
57-
github.com/jackc/pgx/v5 v5.4.1/go.mod h1:q6iHT8uDNXWiFNOlRqJzBTaSH3+2xCXkokxHZC5qWFY=
58-
github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE=
59+
github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
60+
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
61+
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
5962
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
6063
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
6164
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
@@ -95,8 +98,8 @@ github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUo
9598
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
9699
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
97100
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
98-
github.com/prometheus/procfs v0.11.0 h1:5EAgkfkMl659uZPbe9AS2N68a7Cc1TJbPEuGzFuRbyk=
99-
github.com/prometheus/procfs v0.11.0/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
101+
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
102+
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
100103
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
101104
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
102105
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
@@ -111,18 +114,19 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
111114
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
112115
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
113116
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
114-
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
115117
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
118+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
119+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
116120
github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE=
117121
github.com/yuin/gopher-lua v1.1.0/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
118122
github.com/zenizh/go-capturer v0.0.0-20211219060012-52ea6c8fed04 h1:qXafrlZL1WsJW5OokjraLLRURHiw0OzKHD/RNdspp4w=
119123
github.com/zenizh/go-capturer v0.0.0-20211219060012-52ea6c8fed04/go.mod h1:FiwNQxz6hGoNFBC4nIx+CxZhI3nne5RmIOlT/MXcSD4=
120124
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
121125
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
122126
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
123-
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
124-
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
125-
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
127+
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
128+
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
129+
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
126130
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
127131
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
128132
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -132,15 +136,15 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc
132136
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
133137
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
134138
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
135-
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
136-
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
137-
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
138-
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
139+
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
140+
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
141+
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
142+
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
139143
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
140-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 h1:2FZP5XuJY9zQyGM5N0rtovnoXjiMUEIUMvw0m9wlpLc=
141-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130/go.mod h1:8mL13HKkDa+IuJ8yruA3ci0q+0vsUz4m//+ottjwS5o=
142-
google.golang.org/grpc v1.56.2 h1:fVRFRnXvU+x6C4IlHZewvJOVHoOv1TUuQyoRsYnB4bI=
143-
google.golang.org/grpc v1.56.2/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
144+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4=
145+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
146+
google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
147+
google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
144148
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
145149
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
146150
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=

plugin/plugin.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
goplugin "github.com/hashicorp/go-plugin"
1515
"github.com/spf13/cast"
1616
"google.golang.org/grpc"
17-
"google.golang.org/protobuf/types/known/structpb"
1817
)
1918

2019
type Plugin struct {
@@ -64,16 +63,16 @@ func (p *CachePlugin) GRPCClient(_ context.Context, _ *goplugin.GRPCBroker, c *g
6463

6564
// GetPluginConfig returns the plugin config.
6665
func (p *Plugin) GetPluginConfig(
67-
_ context.Context, _ *structpb.Struct,
68-
) (*structpb.Struct, error) {
66+
_ context.Context, _ *v1.Struct,
67+
) (*v1.Struct, error) {
6968
GetPluginConfigCounter.Inc()
70-
return structpb.NewStruct(PluginConfig)
69+
return v1.NewStruct(PluginConfig)
7170
}
7271

7372
// OnTrafficFromClient is called when a request is received by GatewayD from the client.
7473
func (p *Plugin) OnTrafficFromClient(
75-
ctx context.Context, req *structpb.Struct,
76-
) (*structpb.Struct, error) {
74+
ctx context.Context, req *v1.Struct,
75+
) (*v1.Struct, error) {
7776
OnTrafficFromClientCounter.Inc()
7877
req, err := postgres.HandleClientMessage(req, p.Logger)
7978
if err != nil {
@@ -125,19 +124,19 @@ func (p *Plugin) OnTrafficFromClient(
125124
p.invalidateDML(ctx, query)
126125

127126
// Check if the query is cached.
128-
response, err := p.RedisClient.Get(ctx, cacheKey).Result()
127+
response, err := p.RedisClient.Get(ctx, cacheKey).Bytes()
129128
if err != nil {
130129
CacheMissesCounter.Inc()
131130
p.Logger.Debug("Failed to get cached response", "error", err)
132131
}
133132
CacheGetsCounter.Inc()
134133

135134
// If the query is cached, return the cached response.
136-
if response != "" {
135+
if response != nil {
137136
CacheHitsCounter.Inc()
138137
// The response is cached.
139-
req.Fields["response"] = structpb.NewStringValue(response)
140-
req.Fields["terminate"] = structpb.NewBoolValue(true)
138+
req.Fields["response"] = v1.NewBytesValue(response)
139+
req.Fields["terminate"] = v1.NewBoolValue(true)
141140
return req, nil
142141
}
143142
}
@@ -147,8 +146,8 @@ func (p *Plugin) OnTrafficFromClient(
147146

148147
// OnTrafficFromServer is called when a response is received by GatewayD from the server.
149148
func (p *Plugin) OnTrafficFromServer(
150-
ctx context.Context, resp *structpb.Struct,
151-
) (*structpb.Struct, error) {
149+
ctx context.Context, resp *v1.Struct,
150+
) (*v1.Struct, error) {
152151
OnTrafficFromServerCounter.Inc()
153152
resp, err := postgres.HandleServerMessage(resp, p.Logger)
154153
if err != nil {
@@ -158,8 +157,14 @@ func (p *Plugin) OnTrafficFromServer(
158157
rowDescription := cast.ToString(sdkPlugin.GetAttr(resp, "rowDescription", ""))
159158
dataRow := cast.ToStringSlice(sdkPlugin.GetAttr(resp, "dataRow", []interface{}{}))
160159
errorResponse := cast.ToString(sdkPlugin.GetAttr(resp, "errorResponse", ""))
161-
request := cast.ToString(sdkPlugin.GetAttr(resp, "request", ""))
162-
response := cast.ToString(sdkPlugin.GetAttr(resp, "response", ""))
160+
request, ok := sdkPlugin.GetAttr(resp, "request", nil).([]byte)
161+
if !ok {
162+
request = []byte{}
163+
}
164+
response, ok := sdkPlugin.GetAttr(resp, "response", nil).([]byte)
165+
if !ok {
166+
response = []byte{}
167+
}
163168
server := cast.ToStringMapString(sdkPlugin.GetAttr(resp, "server", ""))
164169

165170
// This is used as a fallback if the database is not found in the startup message.
@@ -185,7 +190,7 @@ func (p *Plugin) OnTrafficFromServer(
185190
return resp, nil
186191
}
187192

188-
cacheKey := strings.Join([]string{server["remote"], database, request}, ":")
193+
cacheKey := strings.Join([]string{server["remote"], database, string(request)}, ":")
189194
if errorResponse == "" && rowDescription != "" && dataRow != nil && len(dataRow) > 0 {
190195
// The request was successful and the response contains data. Cache the response.
191196
if err := p.RedisClient.Set(ctx, cacheKey, response, p.Expiry).Err(); err != nil {
@@ -223,7 +228,7 @@ func (p *Plugin) OnTrafficFromServer(
223228
return resp, nil
224229
}
225230

226-
func (p *Plugin) OnClosed(ctx context.Context, req *structpb.Struct) (*structpb.Struct, error) {
231+
func (p *Plugin) OnClosed(ctx context.Context, req *v1.Struct) (*v1.Struct, error) {
227232
OnClosedCounter.Inc()
228233
client := cast.ToStringMapString(sdkPlugin.GetAttr(req, "client", nil))
229234
if client != nil {
@@ -316,7 +321,7 @@ func (p *Plugin) invalidateDML(ctx context.Context, query string) {
316321
// getDBFromStartupMessage gets the database name from the startup message.
317322
func (p *Plugin) getDBFromStartupMessage(
318323
ctx context.Context,
319-
req *structpb.Struct,
324+
req *v1.Struct,
320325
database string,
321326
client map[string]string,
322327
) string {

plugin/plugin_test.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ import (
88

99
miniredis "github.com/alicebob/miniredis/v2"
1010
"github.com/gatewayd-io/gatewayd-plugin-sdk/logging"
11+
v1 "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin/v1"
1112
"github.com/go-redis/redis/v8"
1213
"github.com/hashicorp/go-hclog"
1314
pgproto3 "github.com/jackc/pgx/v5/pgproto3"
1415
"github.com/stretchr/testify/assert"
15-
"google.golang.org/protobuf/types/known/structpb"
1616
)
1717

18-
func testQueryRequest() (string, string) {
18+
func testQueryRequest() (string, []byte) {
1919
query := "SELECT * FROM users"
2020
queryMsg := pgproto3.Query{String: query}
2121
// Encode the data to base64.
22-
return query, base64.StdEncoding.EncodeToString(queryMsg.Encode(nil))
22+
return query, queryMsg.Encode(nil)
2323
}
2424

25-
func testStartupRequest() string {
25+
func testStartupRequest() []byte {
2626
startupMsg := pgproto3.StartupMessage{
2727
ProtocolVersion: 196608,
2828
Parameters: map[string]string{
2929
"user": "postgres",
3030
"database": "postgres",
3131
},
3232
}
33-
return base64.StdEncoding.EncodeToString(startupMsg.Encode(nil))
33+
return startupMsg.Encode(nil)
3434
}
3535

3636
func Test_Plugin(t *testing.T) {
@@ -72,9 +72,8 @@ func Test_Plugin(t *testing.T) {
7272
assert.Equal(t, configMap["categories"], PluginConfig["categories"])
7373

7474
// Test the plugin's OnTrafficFromClient method with a StartupMessage.
75-
startupReq := testStartupRequest()
7675
args := map[string]interface{}{
77-
"request": startupReq,
76+
"request": testStartupRequest(),
7877
"client": map[string]interface{}{
7978
"local": "localhost:15432",
8079
"remote": "localhost:45320",
@@ -85,7 +84,7 @@ func Test_Plugin(t *testing.T) {
8584
},
8685
"error": "",
8786
}
88-
req, err := structpb.NewStruct(args)
87+
req, err := v1.NewStruct(args)
8988
assert.Nil(t, err)
9089
result, err := p.Impl.OnTrafficFromClient(context.Background(), req)
9190
assert.Nil(t, err)
@@ -110,7 +109,7 @@ func Test_Plugin(t *testing.T) {
110109
},
111110
"error": "",
112111
}
113-
req, err = structpb.NewStruct(args)
112+
req, err = v1.NewStruct(args)
114113
assert.Nil(t, err)
115114
result, err = p.Impl.OnTrafficFromClient(context.Background(), req)
116115
assert.Nil(t, err)
@@ -125,7 +124,8 @@ func Test_Plugin(t *testing.T) {
125124
1
126125
(1 row)
127126
*/
128-
response := "VAAAABsAAWlkAAAAQAQAAQAAABcABP////8AAEQAAAALAAEAAAABMUMAAAANU0VMRUNUIDEAWgAAAAVJ"
127+
response, err := base64.StdEncoding.DecodeString("VAAAABsAAWlkAAAAQAQAAQAAABcABP////8AAEQAAAALAAEAAAABMUMAAAANU0VMRUNUIDEAWgAAAAVJ")
128+
assert.Nil(t, err)
129129
args = map[string]interface{}{
130130
"request": request,
131131
"response": response,
@@ -139,16 +139,17 @@ func Test_Plugin(t *testing.T) {
139139
},
140140
"error": "",
141141
}
142-
resp, err := structpb.NewStruct(args)
142+
resp, err := v1.NewStruct(args)
143143
assert.Nil(t, err)
144144
result, err = p.Impl.OnTrafficFromServer(context.Background(), resp)
145145
assert.Nil(t, err)
146146
assert.NotNil(t, result)
147147
assert.Equal(t, result, resp)
148148

149149
// Check that the query and response was cached.
150-
cachedResponse := redisClient.Get(
151-
context.Background(), "localhost:5432:postgres:"+request).Val()
150+
cachedResponse, err := redisClient.Get(
151+
context.Background(), "localhost:5432:postgres:"+string(request)).Bytes()
152+
assert.Nil(t, err)
152153
assert.Equal(t, cachedResponse, response)
153154

154155
// Test the plugin's OnTrafficFromClient method with a cached response.

0 commit comments

Comments
 (0)