Skip to content

Commit fda7ea1

Browse files
committed
feat: use gjson for response parsing
1 parent b252c12 commit fda7ea1

5 files changed

Lines changed: 135 additions & 169 deletions

File tree

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ build-githubmonkey:
1414

1515
.PHONY: azure-githubmonkey
1616
azure-githubmonkey: build-githubmonkey
17-
@cd cmd/server/githubmonkey/.azure && cp -a . ../dist/
17+
@cd cmd/server/githubmonkey/.azure && cp -a . ../dist/
18+
19+
.PHONY: tidy-modules
20+
tidy-modules:
21+
@find . -type d \( -name build -prune \) -o -name go.mod -print | while read -r gomod_path; do \
22+
dir_path=$$(dirname "$$gomod_path"); \
23+
echo "Executing 'go mod tidy' in directory: $$dir_path"; \
24+
(cd "$$dir_path" && GOPROXY=$(GOPROXY) go mod tidy) || exit 1; \
25+
done

cmd/client/apimonkey/instance.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/imroc/req/v3"
1313
"github.com/pkg/errors"
1414
"github.com/rs/zerolog"
15-
"github.com/valyala/fastjson"
15+
"github.com/tidwall/gjson"
1616
"meow.tf/streamdeck/sdk"
1717
)
1818

@@ -82,36 +82,36 @@ func (i *Instance) Run() {
8282
}
8383

8484
lg.Debug().Msgf("got raw response %v", resp.String())
85-
parsed, err := fastjson.ParseBytes(resp.Bytes())
8685
if err != nil {
8786
sdk.ShowAlert(i.contextApp)
8887
lg.Err(errors.Wrap(err, "error parsing request")).Send()
8988
return
9089
}
9190

92-
value := parsed.String()
91+
value := resp.String()
9392
if i.cfg.ResponseJSONSelector != "" {
94-
selectorVal := parsed.Get(i.cfg.ResponseJSONSelector)
95-
if selectorVal == nil || selectorVal.Type() == fastjson.TypeNull {
93+
selectorVal := gjson.Get(resp.String(), i.cfg.ResponseJSONSelector)
94+
95+
if selectorVal.Type == gjson.Null {
9696
sdk.ShowAlert(i.contextApp)
9797
lg.Err(errors.New("no data found by ResponseJSONSelector")).Send()
9898
return
9999
}
100100

101-
if selectorVal.Type() == fastjson.TypeString {
102-
if s, errSBytes := selectorVal.StringBytes(); errSBytes != nil {
101+
if selectorVal.Type == gjson.String {
102+
if str := selectorVal.String(); str != "" {
103103
sdk.ShowAlert(i.contextApp)
104104
lg.Err(errors.Wrap(err, "error parsing StringBytes")).Send()
105105
return
106106
} else {
107-
value = string(s)
107+
value = str
108108
}
109109
} else {
110110
value = selectorVal.String()
111111
}
112112
}
113113

114-
lg.Debug().Msgf("got raw value %v", string(value))
114+
lg.Debug().Msgf("got raw value %v", value)
115115

116116
i.handleResponse(value)
117117
}()

cmd/client/apimonkey/main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ var lg zerolog.Logger
1616
var instances = map[string]*Instance{}
1717
var mut sync.Mutex
1818

19-
//var contextApp string
20-
//var globalConfig *config
21-
2219
func setSettingsFromPayload(payload *fastjson.Value, ctxId string, instance *Instance) {
2320
if instance == nil {
2421
lg.Warn().Msgf("instance %v not found", ctxId)
@@ -39,7 +36,7 @@ func setSettingsFromPayload(payload *fastjson.Value, ctxId string, instance *Ins
3936
func main() {
4037
logFile := &lumberjack.Logger{
4138
Filename: "logs/log.log",
42-
MaxSize: 100,
39+
MaxSize: 30,
4340
MaxBackups: 3,
4441
MaxAge: 10,
4542
Compress: false,

go.mod

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,54 @@
11
module github.com/ft-t/streamdeck
22

3-
go 1.19
3+
go 1.21
44

55
require (
6-
github.com/gofiber/fiber/v2 v2.44.0
6+
github.com/gofiber/fiber/v2 v2.52.2
77
github.com/google/go-github/v38 v38.1.0
8-
github.com/imroc/req/v3 v3.34.0
8+
github.com/imroc/req/v3 v3.43.1
99
github.com/pkg/errors v0.9.1
10-
github.com/rs/zerolog v1.29.1
11-
github.com/stretchr/testify v1.8.2
12-
github.com/valyala/fastjson v1.6.3
13-
golang.org/x/oauth2 v0.7.0
10+
github.com/rs/zerolog v1.32.0
11+
github.com/tidwall/gjson v1.17.1
12+
github.com/valyala/fastjson v1.6.4
13+
golang.org/x/oauth2 v0.18.0
1414
gopkg.in/natefinch/lumberjack.v2 v2.2.1
1515
meow.tf/streamdeck/sdk v0.0.0-20221205105203-dab3b98dc3bd
1616
)
1717

1818
require (
19-
github.com/andybalholm/brotli v1.0.5 // indirect
20-
github.com/davecgh/go-spew v1.1.1 // indirect
19+
github.com/andybalholm/brotli v1.1.0 // indirect
20+
github.com/cloudflare/circl v1.3.7 // indirect
2121
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
22-
github.com/golang/mock v1.6.0 // indirect
23-
github.com/golang/protobuf v1.5.3 // indirect
24-
github.com/google/go-querystring v1.0.0 // indirect
25-
github.com/google/pprof v0.0.0-20230426061923-93006964c1fc // indirect
26-
github.com/google/uuid v1.3.0 // indirect
27-
github.com/gorilla/websocket v1.5.0 // indirect
22+
github.com/golang/protobuf v1.5.4 // indirect
23+
github.com/google/go-querystring v1.1.0 // indirect
24+
github.com/google/pprof v0.0.0-20240320155624-b11c3daa6f07 // indirect
25+
github.com/google/uuid v1.6.0 // indirect
26+
github.com/gorilla/websocket v1.5.1 // indirect
2827
github.com/hashicorp/errwrap v1.1.0 // indirect
2928
github.com/hashicorp/go-multierror v1.1.1 // indirect
30-
github.com/klauspost/compress v1.16.3 // indirect
31-
github.com/kr/pretty v0.3.1 // indirect
29+
github.com/klauspost/compress v1.17.7 // indirect
3230
github.com/mattn/go-colorable v0.1.13 // indirect
33-
github.com/mattn/go-isatty v0.0.18 // indirect
34-
github.com/mattn/go-runewidth v0.0.14 // indirect
35-
github.com/onsi/ginkgo/v2 v2.9.2 // indirect
36-
github.com/philhofer/fwd v1.1.2 // indirect
37-
github.com/pmezard/go-difflib v1.0.0 // indirect
31+
github.com/mattn/go-isatty v0.0.20 // indirect
32+
github.com/mattn/go-runewidth v0.0.15 // indirect
33+
github.com/onsi/ginkgo/v2 v2.17.1 // indirect
3834
github.com/quic-go/qpack v0.4.0 // indirect
39-
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
40-
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
41-
github.com/quic-go/quic-go v0.34.0 // indirect
42-
github.com/rivo/uniseg v0.2.0 // indirect
43-
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
44-
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
45-
github.com/tinylib/msgp v1.1.8 // indirect
35+
github.com/quic-go/quic-go v0.42.0 // indirect
36+
github.com/refraction-networking/utls v1.6.3 // indirect
37+
github.com/rivo/uniseg v0.4.7 // indirect
38+
github.com/stretchr/testify v1.8.2 // indirect
39+
github.com/tidwall/match v1.1.1 // indirect
40+
github.com/tidwall/pretty v1.2.1 // indirect
4641
github.com/valyala/bytebufferpool v1.0.0 // indirect
47-
github.com/valyala/fasthttp v1.45.0 // indirect
42+
github.com/valyala/fasthttp v1.52.0 // indirect
4843
github.com/valyala/tcplisten v1.0.0 // indirect
49-
golang.org/x/crypto v0.8.0 // indirect
50-
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 // indirect
51-
golang.org/x/mod v0.10.0 // indirect
52-
golang.org/x/net v0.9.0 // indirect
53-
golang.org/x/sys v0.7.0 // indirect
54-
golang.org/x/text v0.9.0 // indirect
55-
golang.org/x/tools v0.8.0 // indirect
56-
google.golang.org/appengine v1.6.7 // indirect
57-
google.golang.org/protobuf v1.28.0 // indirect
58-
gopkg.in/yaml.v3 v3.0.1 // indirect
44+
go.uber.org/mock v0.4.0 // indirect
45+
golang.org/x/crypto v0.21.0 // indirect
46+
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 // indirect
47+
golang.org/x/mod v0.16.0 // indirect
48+
golang.org/x/net v0.22.0 // indirect
49+
golang.org/x/sys v0.18.0 // indirect
50+
golang.org/x/text v0.14.0 // indirect
51+
golang.org/x/tools v0.19.0 // indirect
52+
google.golang.org/appengine v1.6.8 // indirect
53+
google.golang.org/protobuf v1.33.0 // indirect
5954
)

0 commit comments

Comments
 (0)