Skip to content

Commit

Permalink
feat: update lib and replace json
Browse files Browse the repository at this point in the history
  • Loading branch information
chowyu12 committed Jun 18, 2022
1 parent 5dc2114 commit b2e79c3
Show file tree
Hide file tree
Showing 6 changed files with 455 additions and 80 deletions.
11 changes: 0 additions & 11 deletions .vscode/settings.json

This file was deleted.

7 changes: 3 additions & 4 deletions broker/comm.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package broker

import (
"encoding/json"
"reflect"
"time"

"github.com/tidwall/gjson"
jsoniter "github.com/json-iterator/go"
"go.uber.org/zap"

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

func unWrapPublishPacket(packet *packets.PublishPacket) *packets.PublishPacket {
p := packet.Copy()
if gjson.GetBytes(p.Payload, "payload").Exists() {
p.Payload = []byte(gjson.GetBytes(p.Payload, "payload").String())
if payload := jsoniter.Get(p.Payload, "payload").ToString(); payload != "" {
p.Payload = []byte(payload)
}
return p
}
Expand Down
4 changes: 3 additions & 1 deletion broker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package broker
import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"errors"
"flag"
"fmt"
Expand All @@ -13,9 +12,12 @@ import (
"github.com/fhmq/hmq/logger"
"github.com/fhmq/hmq/plugins/auth"
"github.com/fhmq/hmq/plugins/bridge"
jsoniter "github.com/json-iterator/go"
"go.uber.org/zap"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary

type Config struct {
Worker int `json:"workerNum"`
HTTPPort string `json:"httpPort"`
Expand Down
28 changes: 14 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ module github.com/fhmq/hmq
go 1.18

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

require (
Expand All @@ -26,32 +26,32 @@ require (
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.0.0 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.1 // indirect
github.com/klauspost/compress v1.15.6 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pierrec/lz4/v4 v4.1.14 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 // indirect
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit b2e79c3

Please sign in to comment.