summaryrefslogtreecommitdiffstats
path: root/modules/private
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-03-01 21:08:10 +0000
committerGitHub <noreply@github.com>2021-03-01 22:08:10 +0100
commitf0e15250b9e322cc7731ba026d12387c2b549a42 (patch)
treef13d46119077ba924d620ef172b91daa315bda0a /modules/private
parent59fd641d1fb021e35aea7f9f4a1916cc11ef5c51 (diff)
downloadgitea-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/private')
-rw-r--r--modules/private/hook.go4
-rw-r--r--modules/private/internal.go3
-rw-r--r--modules/private/mail.go3
-rw-r--r--modules/private/manager.go4
-rw-r--r--modules/private/serv.go4
5 files changed, 13 insertions, 5 deletions
diff --git a/modules/private/hook.go b/modules/private/hook.go
index 84d66943ba..178500f736 100644
--- a/modules/private/hook.go
+++ b/modules/private/hook.go
@@ -5,7 +5,6 @@
package private
import (
- "encoding/json"
"fmt"
"net/http"
"net/url"
@@ -13,6 +12,7 @@ import (
"time"
"code.gitea.io/gitea/modules/setting"
+ jsoniter "github.com/json-iterator/go"
)
// Git environment variables
@@ -80,6 +80,7 @@ func HookPreReceive(ownerName, repoName string, opts HookOptions) (int, string)
)
req := newInternalRequest(reqURL, "POST")
req = req.Header("Content-Type", "application/json")
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
jsonBytes, _ := json.Marshal(opts)
req.Body(jsonBytes)
req.SetTimeout(60*time.Second, time.Duration(60+len(opts.OldCommitIDs))*time.Second)
@@ -106,6 +107,7 @@ func HookPostReceive(ownerName, repoName string, opts HookOptions) (*HookPostRec
req := newInternalRequest(reqURL, "POST")
req = req.Header("Content-Type", "application/json")
req.SetTimeout(60*time.Second, time.Duration(60+len(opts.OldCommitIDs))*time.Second)
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
jsonBytes, _ := json.Marshal(opts)
req.Body(jsonBytes)
resp, err := req.Response()
diff --git a/modules/private/internal.go b/modules/private/internal.go
index b4fee2680f..360fae47b6 100644
--- a/modules/private/internal.go
+++ b/modules/private/internal.go
@@ -6,13 +6,13 @@ package private
import (
"crypto/tls"
- "encoding/json"
"fmt"
"net"
"net/http"
"code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/setting"
+ jsoniter "github.com/json-iterator/go"
)
func newRequest(url, method string) *httplib.Request {
@@ -27,6 +27,7 @@ type Response struct {
func decodeJSONError(resp *http.Response) *Response {
var res Response
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
err := json.NewDecoder(resp.Body).Decode(&res)
if err != nil {
res.Err = err.Error()
diff --git a/modules/private/mail.go b/modules/private/mail.go
index 675dec8f11..9c0912a6e3 100644
--- a/modules/private/mail.go
+++ b/modules/private/mail.go
@@ -5,12 +5,12 @@
package private
import (
- "encoding/json"
"fmt"
"io/ioutil"
"net/http"
"code.gitea.io/gitea/modules/setting"
+ jsoniter "github.com/json-iterator/go"
)
// Email structure holds a data for sending general emails
@@ -32,6 +32,7 @@ func SendEmail(subject, message string, to []string) (int, string) {
req := newInternalRequest(reqURL, "POST")
req = req.Header("Content-Type", "application/json")
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
jsonBytes, _ := json.Marshal(Email{
Subject: subject,
Message: message,
diff --git a/modules/private/manager.go b/modules/private/manager.go
index 6c9ec920bb..2bc6cec3b9 100644
--- a/modules/private/manager.go
+++ b/modules/private/manager.go
@@ -5,13 +5,13 @@
package private
import (
- "encoding/json"
"fmt"
"net/http"
"net/url"
"time"
"code.gitea.io/gitea/modules/setting"
+ jsoniter "github.com/json-iterator/go"
)
// Shutdown calls the internal shutdown function
@@ -65,6 +65,7 @@ func FlushQueues(timeout time.Duration, nonBlocking bool) (int, string) {
req.SetTimeout(timeout+10*time.Second, timeout+10*time.Second)
}
req = req.Header("Content-Type", "application/json")
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
jsonBytes, _ := json.Marshal(FlushOptions{
Timeout: timeout,
NonBlocking: nonBlocking,
@@ -151,6 +152,7 @@ func AddLogger(group, name, mode string, config map[string]interface{}) (int, st
req := newInternalRequest(reqURL, "POST")
req = req.Header("Content-Type", "application/json")
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
jsonBytes, _ := json.Marshal(LoggerOptions{
Group: group,
Name: name,
diff --git a/modules/private/serv.go b/modules/private/serv.go
index 235d99a2b9..e077b00ccc 100644
--- a/modules/private/serv.go
+++ b/modules/private/serv.go
@@ -5,13 +5,13 @@
package private
import (
- "encoding/json"
"fmt"
"net/http"
"net/url"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/setting"
+ jsoniter "github.com/json-iterator/go"
)
// KeyAndOwner is the response from ServNoCommand
@@ -34,6 +34,7 @@ func ServNoCommand(keyID int64) (*models.PublicKey, *models.User, error) {
}
var keyAndOwner KeyAndOwner
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.NewDecoder(resp.Body).Decode(&keyAndOwner); err != nil {
return nil, nil, err
}
@@ -90,6 +91,7 @@ func ServCommand(keyID int64, ownerName, repoName string, mode models.AccessMode
return nil, err
}
defer resp.Body.Close()
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
if resp.StatusCode != http.StatusOK {
var errServCommand ErrServCommand
if err := json.NewDecoder(resp.Body).Decode(&errServCommand); err != nil {