diff --git a/api-notification.go b/api-notification.go index 57ac1ed37..8514461d7 100644 --- a/api-notification.go +++ b/api-notification.go @@ -20,11 +20,11 @@ package minio import ( "bufio" "context" - "encoding/json" "net/http" "net/url" "time" + jsoniter "github.com/json-iterator/go" "github.com/minio/minio-go/v6/pkg/s3utils" ) @@ -203,6 +203,7 @@ func (c Client) ListenBucketNotification(bucketName, prefix, suffix string, even // Use a higher buffer to support unexpected // caching done by proxies bio.Buffer(notificationEventBuffer, notificationCapacity) + var json = jsoniter.ConfigCompatibleWithStandardLibrary // Unmarshal each line, returns marshalled values. for bio.Scan() { diff --git a/functional_tests.go b/functional_tests.go index ca66bc6fd..bd7683c18 100644 --- a/functional_tests.go +++ b/functional_tests.go @@ -22,7 +22,6 @@ package main import ( "bytes" "context" - "encoding/json" "errors" "fmt" "io" @@ -40,6 +39,7 @@ import ( "time" "github.com/dustin/go-humanize" + jsoniter "github.com/json-iterator/go" log "github.com/sirupsen/logrus" "github.com/minio/minio-go/v6" @@ -75,7 +75,7 @@ func (f *mintJSONFormatter) Format(entry *log.Entry) ([]byte, error) { data[k] = v } } - + var json = jsoniter.ConfigCompatibleWithStandardLibrary serialized, err := json.Marshal(data) if err != nil { return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err) diff --git a/go.mod b/go.mod index fe6d38bc6..fe43a735e 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.12 require ( github.com/dustin/go-humanize v1.0.0 // indirect + github.com/json-iterator/go v1.1.9 github.com/minio/sha256-simd v0.1.1 github.com/mitchellh/go-homedir v1.1.0 github.com/sirupsen/logrus v1.5.0 // indirect diff --git a/go.sum b/go.sum index 57de3a2b9..7461ddbf1 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,13 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -10,6 +15,11 @@ github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKU github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q= github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo= @@ -17,7 +27,10 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f h1:R423Cnkcp5JABoeemiGEPlt9tHXFfw5kvc0yqlxRPWo= golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= diff --git a/pkg/credentials/file_minio_client.go b/pkg/credentials/file_minio_client.go index 8adb5dcb1..ca6db005b 100644 --- a/pkg/credentials/file_minio_client.go +++ b/pkg/credentials/file_minio_client.go @@ -18,12 +18,12 @@ package credentials import ( - "encoding/json" "io/ioutil" "os" "path/filepath" "runtime" + jsoniter "github.com/json-iterator/go" homedir "github.com/mitchellh/go-homedir" ) @@ -122,6 +122,8 @@ type config struct { // returned if it fails to read from the file. func loadAlias(filename, alias string) (hostConfig, error) { cfg := &config{} + var json = jsoniter.ConfigCompatibleWithStandardLibrary + configBytes, err := ioutil.ReadFile(filename) if err != nil { return hostConfig{}, err diff --git a/pkg/credentials/iam_aws.go b/pkg/credentials/iam_aws.go index 60f78f808..a7eb8cb9a 100644 --- a/pkg/credentials/iam_aws.go +++ b/pkg/credentials/iam_aws.go @@ -19,7 +19,6 @@ package credentials import ( "bufio" - "encoding/json" "errors" "fmt" "io/ioutil" @@ -29,6 +28,8 @@ import ( "os" "path" "time" + + jsoniter "github.com/json-iterator/go" ) // DefaultExpiryWindow - Default expiry window. @@ -227,7 +228,7 @@ func getEcsTaskCredentials(client *http.Client, endpoint string) (ec2RoleCredRes } respCreds := ec2RoleCredRespBody{} - if err := json.NewDecoder(resp.Body).Decode(&respCreds); err != nil { + if err := jsoniter.NewDecoder(resp.Body).Decode(&respCreds); err != nil { return ec2RoleCredRespBody{}, err } @@ -283,7 +284,7 @@ func getCredentials(client *http.Client, endpoint string) (ec2RoleCredRespBody, } respCreds := ec2RoleCredRespBody{} - if err := json.NewDecoder(resp.Body).Decode(&respCreds); err != nil { + if err := jsoniter.NewDecoder(resp.Body).Decode(&respCreds); err != nil { return ec2RoleCredRespBody{}, err } diff --git a/pkg/encrypt/server-side.go b/pkg/encrypt/server-side.go index cabc65067..5276f63fc 100644 --- a/pkg/encrypt/server-side.go +++ b/pkg/encrypt/server-side.go @@ -20,10 +20,10 @@ package encrypt import ( "crypto/md5" "encoding/base64" - "encoding/json" "errors" "net/http" + jsoniter "github.com/json-iterator/go" "golang.org/x/crypto/argon2" ) @@ -101,6 +101,7 @@ func NewSSEKMS(keyID string, context interface{}) (ServerSide, error) { if context == nil { return kms{key: keyID, hasContext: false}, nil } + var json = jsoniter.ConfigCompatibleWithStandardLibrary serializedContext, err := json.Marshal(context) if err != nil { return nil, err diff --git a/pkg/policy/bucket-policy-condition_test.go b/pkg/policy/bucket-policy-condition_test.go index 2fc9baa60..db24cf364 100644 --- a/pkg/policy/bucket-policy-condition_test.go +++ b/pkg/policy/bucket-policy-condition_test.go @@ -18,12 +18,14 @@ package policy import ( - "encoding/json" "testing" + jsoniter "github.com/json-iterator/go" "github.com/minio/minio-go/v6/pkg/set" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary + // ConditionKeyMap.Add() is called and the result is validated. func TestConditionKeyMapAdd(t *testing.T) { condKeyMap := make(ConditionKeyMap) diff --git a/pkg/policy/bucket-policy.go b/pkg/policy/bucket-policy.go index f2c728924..f318be2a0 100644 --- a/pkg/policy/bucket-policy.go +++ b/pkg/policy/bucket-policy.go @@ -18,11 +18,11 @@ package policy import ( - "encoding/json" "errors" "reflect" "strings" + jsoniter "github.com/json-iterator/go" "github.com/minio/minio-go/v6/pkg/set" ) @@ -88,7 +88,8 @@ type User struct { // the reason is that Principal can take a json struct represented by // User string but it can also take a string. func (u *User) UnmarshalJSON(data []byte) error { - // Try to unmarshal data in a struct equal to User, we need it + // Try to unmarshal data in a struct equal to User, + var json = jsoniter.ConfigCompatibleWithStandardLibrary // to avoid infinite recursive call of this function type AliasUser User var au AliasUser diff --git a/pkg/policy/bucket-policy_test.go b/pkg/policy/bucket-policy_test.go index a514eaa0f..7d0a9cbfb 100644 --- a/pkg/policy/bucket-policy_test.go +++ b/pkg/policy/bucket-policy_test.go @@ -18,7 +18,6 @@ package policy import ( - "encoding/json" "fmt" "reflect" "testing" diff --git a/pkg/set/stringset.go b/pkg/set/stringset.go index e220271bb..c35e58e1a 100644 --- a/pkg/set/stringset.go +++ b/pkg/set/stringset.go @@ -18,14 +18,17 @@ package set import ( - "encoding/json" "fmt" "sort" + + jsoniter "github.com/json-iterator/go" ) // StringSet - uses map as set of strings. type StringSet map[string]struct{} +var json = jsoniter.ConfigCompatibleWithStandardLibrary + // ToSlice - returns StringSet as string slice. func (set StringSet) ToSlice() []string { keys := make([]string, 0, len(set))