Skip to content

Commit b2e79c3

Browse files
committedJun 18, 2022
feat: update lib and replace json
1 parent 5dc2114 commit b2e79c3

File tree

6 files changed

+455
-80
lines changed

6 files changed

+455
-80
lines changed
 

‎.vscode/settings.json

-11
This file was deleted.

‎broker/comm.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package broker
22

33
import (
4-
"encoding/json"
54
"reflect"
65
"time"
76

8-
"github.com/tidwall/gjson"
7+
jsoniter "github.com/json-iterator/go"
98
"go.uber.org/zap"
109

1110
"github.com/eclipse/paho.mqtt.golang/packets"
@@ -134,8 +133,8 @@ func wrapPublishPacket(packet *packets.PublishPacket) *packets.PublishPacket {
134133

135134
func unWrapPublishPacket(packet *packets.PublishPacket) *packets.PublishPacket {
136135
p := packet.Copy()
137-
if gjson.GetBytes(p.Payload, "payload").Exists() {
138-
p.Payload = []byte(gjson.GetBytes(p.Payload, "payload").String())
136+
if payload := jsoniter.Get(p.Payload, "payload").ToString(); payload != "" {
137+
p.Payload = []byte(payload)
139138
}
140139
return p
141140
}

‎broker/config.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package broker
33
import (
44
"crypto/tls"
55
"crypto/x509"
6-
"encoding/json"
76
"errors"
87
"flag"
98
"fmt"
@@ -13,9 +12,12 @@ import (
1312
"github.com/fhmq/hmq/logger"
1413
"github.com/fhmq/hmq/plugins/auth"
1514
"github.com/fhmq/hmq/plugins/bridge"
15+
jsoniter "github.com/json-iterator/go"
1616
"go.uber.org/zap"
1717
)
1818

19+
var json = jsoniter.ConfigCompatibleWithStandardLibrary
20+
1921
type Config struct {
2022
Worker int `json:"workerNum"`
2123
HTTPPort string `json:"httpPort"`

‎go.mod

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ module github.com/fhmq/hmq
33
go 1.18
44

55
require (
6-
github.com/Shopify/sarama v1.32.0
6+
github.com/Shopify/sarama v1.34.1
77
github.com/bitly/go-simplejson v0.5.0
88
github.com/cespare/xxhash/v2 v2.1.2
99
github.com/eapache/queue v1.1.0
10-
github.com/eclipse/paho.mqtt.golang v1.3.5
11-
github.com/gin-gonic/gin v1.7.7
10+
github.com/eclipse/paho.mqtt.golang v1.4.1
11+
github.com/gin-gonic/gin v1.8.1
1212
github.com/google/uuid v1.3.0
13+
github.com/json-iterator/go v1.1.12
1314
github.com/patrickmn/go-cache v2.1.0+incompatible
14-
github.com/stretchr/testify v1.7.1
15-
github.com/tidwall/gjson v1.14.0
15+
github.com/stretchr/testify v1.7.2
1616
go.uber.org/zap v1.21.0
17-
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3
17+
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9
1818
)
1919

2020
require (
@@ -26,32 +26,32 @@ require (
2626
github.com/go-playground/locales v0.14.0 // indirect
2727
github.com/go-playground/universal-translator v0.18.0 // indirect
2828
github.com/go-playground/validator/v10 v10.10.1 // indirect
29-
github.com/golang/protobuf v1.5.2 // indirect
29+
github.com/goccy/go-json v0.9.7 // indirect
3030
github.com/golang/snappy v0.0.4 // indirect
31+
github.com/hashicorp/errwrap v1.0.0 // indirect
32+
github.com/hashicorp/go-multierror v1.1.1 // indirect
3133
github.com/hashicorp/go-uuid v1.0.3 // indirect
3234
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
3335
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
3436
github.com/jcmturner/gofork v1.0.0 // indirect
3537
github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect
3638
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
37-
github.com/json-iterator/go v1.1.12 // indirect
38-
github.com/klauspost/compress v1.15.1 // indirect
39+
github.com/klauspost/compress v1.15.6 // indirect
3940
github.com/leodido/go-urn v1.2.1 // indirect
4041
github.com/mattn/go-isatty v0.0.14 // indirect
4142
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4243
github.com/modern-go/reflect2 v1.0.2 // indirect
43-
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
44+
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
45+
github.com/pierrec/lz4/v4 v4.1.14 // indirect
4446
github.com/pmezard/go-difflib v1.0.0 // indirect
4547
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
46-
github.com/tidwall/match v1.1.1 // indirect
47-
github.com/tidwall/pretty v1.2.0 // indirect
4848
github.com/ugorji/go/codec v1.2.7 // indirect
4949
go.uber.org/atomic v1.9.0 // indirect
5050
go.uber.org/multierr v1.8.0 // indirect
5151
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 // indirect
52-
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f // indirect
52+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
5353
golang.org/x/text v0.3.7 // indirect
5454
google.golang.org/protobuf v1.28.0 // indirect
5555
gopkg.in/yaml.v2 v2.4.0 // indirect
56-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
56+
gopkg.in/yaml.v3 v3.0.1 // indirect
5757
)

0 commit comments

Comments
 (0)
Please sign in to comment.