Skip to content

Commit a13e105

Browse files
committed
add jsoniter
1 parent fcc74ae commit a13e105

File tree

10 files changed

+54
-10
lines changed

10 files changed

+54
-10
lines changed

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ require (
5656

5757
require (
5858
cloud.google.com/go/pubsub v1.30.0
59+
github.com/goccy/go-json v0.10.2
60+
github.com/json-iterator/go v1.1.12
5961
github.com/newrelic/go-agent v2.1.0+incompatible
6062
gorm.io/driver/mysql v1.4.5
6163
gorm.io/driver/postgres v1.4.6
@@ -111,6 +113,8 @@ require (
111113
github.com/mailru/easyjson v0.7.7 // indirect
112114
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
113115
github.com/mitchellh/mapstructure v1.5.0 // indirect
116+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
117+
github.com/modern-go/reflect2 v1.0.2 // indirect
114118
github.com/oklog/ulid v1.3.1 // indirect
115119
github.com/pierrec/lz4/v4 v4.1.17 // indirect
116120
github.com/pkg/errors v0.9.1 // indirect

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWe
174174
github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ=
175175
github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
176176
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
177+
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
178+
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
177179
github.com/gohttp/pprof v0.0.0-20141119085724-c9d246cbb3ba h1:OckY4Dk1WhEEEz4zYYMsXG5f6necMtGAyAs19vcpRXk=
178180
github.com/gohttp/pprof v0.0.0-20141119085724-c9d246cbb3ba/go.mod h1:V97TX7IXWIioKfmy0IKnnBzsC1jRXP2VicslN9O8IIQ=
179181
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@@ -213,6 +215,7 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
213215
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
214216
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
215217
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
218+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
216219
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
217220
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
218221
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
@@ -278,6 +281,8 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
278281
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
279282
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
280283
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
284+
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
285+
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
281286
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
282287
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
283288
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
@@ -313,6 +318,11 @@ github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
313318
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
314319
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
315320
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
321+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
322+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
323+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
324+
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
325+
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
316326
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
317327
github.com/newrelic/go-agent v2.1.0+incompatible h1:fCuxXeM4eeIKPbzffOWW6y2Dj+eYfc3yylgNZACZqkM=
318328
github.com/newrelic/go-agent v2.1.0+incompatible/go.mod h1:a8Fv1b/fYhFSReoTU6HDkTYIMZeSVNffmoS726Y0LzQ=

pkg/entity/flag_snapshot.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package entity
22

33
import (
4-
"encoding/json"
54
"fmt"
6-
5+
jsoniter "github.com/json-iterator/go"
76
"github.com/openflagr/flagr/pkg/config"
87
"github.com/openflagr/flagr/pkg/util"
98
"github.com/sirupsen/logrus"
@@ -21,6 +20,8 @@ type FlagSnapshot struct {
2120

2221
// SaveFlagSnapshot saves the Flag Snapshot
2322
func SaveFlagSnapshot(db *gorm.DB, flagID uint, updatedBy string) {
23+
var json = jsoniter.ConfigFastest
24+
2425
tx := db.Begin()
2526
f := &Flag{}
2627
if err := tx.First(f, flagID).Error; err != nil {

pkg/entity/variant.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package entity
22

33
import (
44
"database/sql/driver"
5-
"encoding/json"
65
"fmt"
6+
jsoniter "github.com/json-iterator/go"
77

88
"github.com/openflagr/flagr/pkg/util"
99
"github.com/spf13/cast"
@@ -32,6 +32,8 @@ type Attachment map[string]interface{}
3232

3333
// Scan implements scanner interface
3434
func (a *Attachment) Scan(value interface{}) error {
35+
var json = jsoniter.ConfigFastest
36+
3537
if value == nil {
3638
return nil
3739
}
@@ -44,6 +46,8 @@ func (a *Attachment) Scan(value interface{}) error {
4446

4547
// Value implements valuer interface
4648
func (a Attachment) Value() (driver.Value, error) {
49+
var json = jsoniter.ConfigFastest
50+
4751
bytes, err := json.Marshal(a)
4852
if err != nil {
4953
return nil, err

pkg/handler/crud_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package handler
22

33
import (
4-
"encoding/json"
54
"fmt"
5+
jsoniter "github.com/json-iterator/go"
66
"testing"
77

88
"github.com/openflagr/flagr/pkg/entity"
@@ -464,6 +464,8 @@ func TestFindFlags(t *testing.T) {
464464
}
465465

466466
func TestGetFlagSnapshots(t *testing.T) {
467+
var json = jsoniter.ConfigFastest
468+
467469
var res middleware.Responder
468470
db := entity.NewTestDB()
469471
c := &crud{}

pkg/handler/data_record_frame.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package handler
33
import (
44
"encoding/base64"
55
"encoding/json"
6-
76
"github.com/brandur/simplebox"
7+
8+
jsoniter "github.com/json-iterator/go"
89
"github.com/openflagr/flagr/pkg/util"
910
"github.com/openflagr/flagr/swagger_gen/models"
1011
)
@@ -56,6 +57,8 @@ type DataRecordFrame struct {
5657

5758
// MarshalJSON defines the behavior of MarshalJSON for DataRecordFrame
5859
func (drf *DataRecordFrame) MarshalJSON() ([]byte, error) {
60+
var json = jsoniter.ConfigFastest
61+
5962
payload, err := drf.evalResult.MarshalBinary()
6063
if err != nil {
6164
return nil, err
@@ -94,5 +97,6 @@ func (drf *DataRecordFrame) GetPartitionKey() string {
9497

9598
// Output sets the paylaod using its input and returns the json marshal bytes
9699
func (drf *DataRecordFrame) Output() ([]byte, error) {
100+
var json = jsoniter.ConfigFastest
97101
return json.Marshal(drf)
98102
}

pkg/handler/eval.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package handler
22

33
import (
4-
"encoding/json"
54
"fmt"
5+
jsoniter "github.com/json-iterator/go"
66
"math/rand"
77
"sync"
88
"time"
@@ -318,6 +318,7 @@ func debugConstraintMsg(enableDebug bool, expr conditions.Expr, m map[string]int
318318
var rateLimitMap = sync.Map{}
319319

320320
var rateLimitPerFlagConsoleLogging = func(r *models.EvalResult) {
321+
var json = jsoniter.ConfigFastest
321322
flagID := util.SafeUint(r.FlagID)
322323
rl, _ := rateLimitMap.LoadOrStore(flagID, ratelimit.New(
323324
config.Config.RateLimiterPerFlagPerSecondConsoleLogging,

pkg/handler/eval_cache_fetcher.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package handler
22

33
import (
4-
"encoding/json"
54
"fmt"
5+
jsoniter "github.com/json-iterator/go"
66
"io"
77
"net/http"
88
"os"
@@ -97,6 +97,8 @@ type jsonFileFetcher struct {
9797
}
9898

9999
func (ff *jsonFileFetcher) fetch() ([]entity.Flag, error) {
100+
var json = jsoniter.ConfigFastest
101+
100102
b, err := os.ReadFile(ff.filePath)
101103
if err != nil {
102104
return nil, err
@@ -114,6 +116,8 @@ type jsonHTTPFetcher struct {
114116
}
115117

116118
func (hf *jsonHTTPFetcher) fetch() ([]entity.Flag, error) {
119+
var json = jsoniter.ConfigFastest
120+
117121
client := http.Client{Timeout: config.Config.EvalCacheRefreshTimeout}
118122
res, err := client.Get(hf.url)
119123
if err != nil {

pkg/mapper/entity_restapi/e2r/e2r.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package e2r
22

33
import (
4-
"encoding/json"
4+
jsoniter "github.com/json-iterator/go"
55
"time"
66

77
"github.com/go-openapi/strfmt"
@@ -46,6 +46,7 @@ func MapFlags(e []entity.Flag) ([]*models.Flag, error) {
4646

4747
// MapFlagSnapshot maps flag snapshot
4848
func MapFlagSnapshot(e *entity.FlagSnapshot) (*models.FlagSnapshot, error) {
49+
var json = jsoniter.ConfigFastest
4950
ef := &entity.Flag{}
5051
if err := json.Unmarshal(e.Flag, ef); err != nil {
5152
return nil, err

swagger_gen/restapi/configure_flagr.go

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)