Migrate to use jsoniter instead of encoding/json (#14841)

* Migrate to use jsoniter

* fix tests

* update gitea.com/go-chi/binding

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
zeripath 2021-03-01 21:08:10 +00:00 committed by GitHub
parent 59fd641d1f
commit f0e15250b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
77 changed files with 264 additions and 82 deletions

View file

@ -5,7 +5,6 @@
package lfs
import (
"encoding/json"
"strconv"
"strings"
@ -15,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
jsoniter "github.com/json-iterator/go"
)
//checkIsValidRequest check if it a valid request in case of bad request it write the response to ctx.
@ -184,6 +184,7 @@ func PostLockHandler(ctx *context.Context) {
var req api.LFSLockRequest
bodyReader := ctx.Req.Body
defer bodyReader.Close()
json := jsoniter.ConfigCompatibleWithStandardLibrary
dec := json.NewDecoder(bodyReader)
if err := dec.Decode(&req); err != nil {
log.Warn("Failed to decode lock request as json. Error: %v", err)
@ -319,6 +320,7 @@ func UnLockHandler(ctx *context.Context) {
var req api.LFSLockDeleteRequest
bodyReader := ctx.Req.Body
defer bodyReader.Close()
json := jsoniter.ConfigCompatibleWithStandardLibrary
dec := json.NewDecoder(bodyReader)
if err := dec.Decode(&req); err != nil {
log.Warn("Failed to decode lock request as json. Error: %v", err)

View file

@ -6,7 +6,6 @@ package lfs
import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
@ -23,6 +22,7 @@ import (
"code.gitea.io/gitea/modules/storage"
"github.com/dgrijalva/jwt-go"
jsoniter "github.com/json-iterator/go"
)
const (
@ -233,6 +233,7 @@ func getMetaHandler(ctx *context.Context) {
ctx.Resp.Header().Set("Content-Type", metaMediaType)
if ctx.Req.Method == "GET" {
json := jsoniter.ConfigCompatibleWithStandardLibrary
enc := json.NewEncoder(ctx.Resp)
if err := enc.Encode(Represent(rv, meta, true, false)); err != nil {
log.Error("Failed to encode representation as json. Error: %v", err)
@ -304,6 +305,7 @@ func PostHandler(ctx *context.Context) {
}
ctx.Resp.WriteHeader(sentStatus)
json := jsoniter.ConfigCompatibleWithStandardLibrary
enc := json.NewEncoder(ctx.Resp)
if err := enc.Encode(Represent(rv, meta, meta.Existing, true)); err != nil {
log.Error("Failed to encode representation as json. Error: %v", err)
@ -394,6 +396,7 @@ func BatchHandler(ctx *context.Context) {
respobj := &BatchResponse{Objects: responseObjects}
json := jsoniter.ConfigCompatibleWithStandardLibrary
enc := json.NewEncoder(ctx.Resp)
if err := enc.Encode(respobj); err != nil {
log.Error("Failed to encode representation as json. Error: %v", err)
@ -531,6 +534,7 @@ func unpack(ctx *context.Context) *RequestVars {
var p RequestVars
bodyReader := r.Body
defer bodyReader.Close()
json := jsoniter.ConfigCompatibleWithStandardLibrary
dec := json.NewDecoder(bodyReader)
err := dec.Decode(&p)
if err != nil {
@ -554,6 +558,7 @@ func unpackbatch(ctx *context.Context) *BatchVars {
bodyReader := r.Body
defer bodyReader.Close()
json := jsoniter.ConfigCompatibleWithStandardLibrary
dec := json.NewDecoder(bodyReader)
err := dec.Decode(&bv)
if err != nil {