diff options
author | zeripath <art27@cantab.net> | 2021-03-01 21:08:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-01 22:08:10 +0100 |
commit | f0e15250b9e322cc7731ba026d12387c2b549a42 (patch) | |
tree | f13d46119077ba924d620ef172b91daa315bda0a /modules/lfs | |
parent | 59fd641d1fb021e35aea7f9f4a1916cc11ef5c51 (diff) | |
download | gitea-f0e15250b9e322cc7731ba026d12387c2b549a42.tar.gz gitea-f0e15250b9e322cc7731ba026d12387c2b549a42.zip |
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>
Diffstat (limited to 'modules/lfs')
-rw-r--r-- | modules/lfs/locks.go | 4 | ||||
-rw-r--r-- | modules/lfs/server.go | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/modules/lfs/locks.go b/modules/lfs/locks.go index cf62492c7e..f2688c3260 100644 --- a/modules/lfs/locks.go +++ b/modules/lfs/locks.go @@ -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) diff --git a/modules/lfs/server.go b/modules/lfs/server.go index be21a4de82..45cba9d9b7 100644 --- a/modules/lfs/server.go +++ b/modules/lfs/server.go @@ -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 { |