use json unmarshal/marshal from jsoniter in hotpaths (#12269)

This commit is contained in:
Harshavardhana 2021-05-11 02:02:32 -07:00 committed by GitHub
parent 14849b9b2c
commit b81fada834
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 16 additions and 4 deletions

View file

@ -24,6 +24,7 @@ import (
"net/http"
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
"github.com/minio/madmin-go"
"github.com/minio/minio/cmd/logger"
iampolicy "github.com/minio/minio/pkg/iam/policy"
@ -154,6 +155,7 @@ func (a adminAPIHandlers) SetRemoteTargetHandler(w http.ResponseWriter, r *http.
return
}
var target madmin.BucketTarget
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err = json.Unmarshal(reqBytes, &target); err != nil {
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErrWithErr(ErrAdminConfigBadJSON, err), r.URL)
return

View file

@ -21,11 +21,11 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"net/http"
"sync"
"time"
jsoniter "github.com/json-iterator/go"
"github.com/minio/madmin-go"
minio "github.com/minio/minio-go/v7"
miniogo "github.com/minio/minio-go/v7"
@ -386,6 +386,7 @@ func parseBucketTargetConfig(bucket string, cdata, cmetadata []byte) (*madmin.Bu
return nil, nil
}
data = cdata
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if len(cmetadata) != 0 {
if err := json.Unmarshal(cmetadata, &meta); err != nil {
return nil, err

View file

@ -21,11 +21,11 @@ import (
"bytes"
"crypto/rand"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"io"
jsoniter "github.com/json-iterator/go"
"github.com/minio/minio/pkg/fips"
"github.com/minio/minio/pkg/kms"
"github.com/secure-io/sio-go"
@ -88,6 +88,7 @@ func Encrypt(KMS kms.KMS, plaintext io.Reader, context kms.Context) (io.Reader,
header [5]byte
buffer bytes.Buffer
)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
metadata, err := json.Marshal(encryptedObject{
KeyID: key.KeyID,
KMSKey: key.Ciphertext,
@ -139,6 +140,7 @@ func Decrypt(KMS kms.KMS, ciphertext io.Reader, context kms.Context) (io.Reader,
if _, err := io.ReadFull(ciphertext, metadataBuffer); err != nil {
return nil, err
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(metadataBuffer, &metadata); err != nil {
return nil, err
}

View file

@ -20,7 +20,6 @@ package cmd
import (
"bytes"
"context"
"encoding/json"
"net/http"
jsoniter "github.com/json-iterator/go"
@ -41,6 +40,7 @@ const (
// storeDataUsageInBackend will store all objects sent on the gui channel until closed.
func storeDataUsageInBackend(ctx context.Context, objAPI ObjectLayer, dui <-chan madmin.DataUsageInfo) {
for dataUsageInfo := range dui {
var json = jsoniter.ConfigCompatibleWithStandardLibrary
dataUsageJSON, err := json.Marshal(dataUsageInfo)
if err != nil {
logger.LogIf(ctx, err)

View file

@ -29,6 +29,7 @@ import (
"unicode/utf8"
jwtgo "github.com/dgrijalva/jwt-go"
jsoniter "github.com/json-iterator/go"
"github.com/minio/madmin-go"
"github.com/minio/minio-go/v7/pkg/set"
"github.com/minio/minio/cmd/config"
@ -124,6 +125,7 @@ func getIAMConfig(item interface{}, data []byte, itemPath string) error {
}
}
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
return json.Unmarshal(data, item)
}

View file

@ -28,6 +28,7 @@ import (
"time"
"unicode/utf8"
jsoniter "github.com/json-iterator/go"
"github.com/minio/madmin-go"
"github.com/minio/minio/cmd/config"
"github.com/minio/minio/cmd/logger"
@ -244,6 +245,7 @@ func (iamOS *IAMObjectStore) loadIAMConfig(ctx context.Context, item interface{}
}
}
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
return json.Unmarshal(data, item)
}

View file

@ -26,7 +26,6 @@ import (
"crypto"
"crypto/hmac"
"encoding/base64"
"encoding/json"
"fmt"
"strings"
"sync"
@ -188,6 +187,7 @@ func (c *MapClaims) Map() map[string]interface{} {
// MarshalJSON marshals the MapClaims struct
func (c *MapClaims) MarshalJSON() ([]byte, error) {
var json = jsoniter.ConfigCompatibleWithStandardLibrary
return json.Marshal(c.MapClaims)
}

View file

@ -23,6 +23,7 @@ import (
"net/http"
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
"github.com/minio/madmin-go"
"github.com/minio/minio/cmd/logger"
iampolicy "github.com/minio/minio/pkg/iam/policy"
@ -85,6 +86,7 @@ func (api adminAPIHandlers) AddTierHandler(w http.ResponseWriter, r *http.Reques
}
var cfg madmin.TierConfig
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(reqBytes, &cfg); err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
@ -164,6 +166,7 @@ func (api adminAPIHandlers) EditTierHandler(w http.ResponseWriter, r *http.Reque
}
var creds madmin.TierCreds
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(reqBytes, &creds); err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return