summaryrefslogtreecommitdiffstats
path: root/modules/private
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-07-25 00:03:58 +0800
committerGitHub <noreply@github.com>2021-07-24 18:03:58 +0200
commit9f31f3aa8ac4f6bfc8390c9ae63b2a387b414c88 (patch)
tree6f27dc68a35d1f9d806c632e36f0edc8543184ea /modules/private
parente0f9635c0691cb67f0fcbb758cabba801d9fc51b (diff)
downloadgitea-9f31f3aa8ac4f6bfc8390c9ae63b2a387b414c88.tar.gz
gitea-9f31f3aa8ac4f6bfc8390c9ae63b2a387b414c88.zip
Add an abstract json layout to make it's easier to change json library (#16528)
* Add an abstract json layout to make it's easier to change json library * Fix import * Fix import sequence * Fix blank lines * Fix blank lines
Diffstat (limited to 'modules/private')
-rw-r--r--modules/private/hook.go5
-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/restore_repo.go3
-rw-r--r--modules/private/serv.go5
6 files changed, 7 insertions, 16 deletions
diff --git a/modules/private/hook.go b/modules/private/hook.go
index 79fae052dd..9596f5f4da 100644
--- a/modules/private/hook.go
+++ b/modules/private/hook.go
@@ -6,15 +6,14 @@ package private
import (
"context"
- "encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"time"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
- jsoniter "github.com/json-iterator/go"
)
// Git environment variables
@@ -88,7 +87,6 @@ func HookPreReceive(ctx context.Context, ownerName, repoName string, opts HookOp
)
req := newInternalRequest(ctx, 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)
@@ -115,7 +113,6 @@ func HookPostReceive(ctx context.Context, ownerName, repoName string, opts HookO
req := newInternalRequest(ctx, 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 672ac74970..f5b5db0ca1 100644
--- a/modules/private/internal.go
+++ b/modules/private/internal.go
@@ -12,8 +12,8 @@ import (
"net/http"
"code.gitea.io/gitea/modules/httplib"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
- jsoniter "github.com/json-iterator/go"
)
func newRequest(ctx context.Context, url, method string) *httplib.Request {
@@ -30,7 +30,6 @@ 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 4a5a3eedd7..7e229396e3 100644
--- a/modules/private/mail.go
+++ b/modules/private/mail.go
@@ -10,8 +10,8 @@ import (
"io/ioutil"
"net/http"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
- jsoniter "github.com/json-iterator/go"
)
// Email structure holds a data for sending general emails
@@ -33,7 +33,6 @@ func SendEmail(ctx context.Context, subject, message string, to []string) (int,
req := newInternalRequest(ctx, 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 0bcc3f8112..337b0dac64 100644
--- a/modules/private/manager.go
+++ b/modules/private/manager.go
@@ -11,8 +11,8 @@ import (
"net/url"
"time"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
- jsoniter "github.com/json-iterator/go"
)
// Shutdown calls the internal shutdown function
@@ -66,7 +66,6 @@ func FlushQueues(ctx context.Context, timeout time.Duration, nonBlocking bool) (
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,
@@ -153,7 +152,6 @@ func AddLogger(ctx context.Context, group, name, mode string, config map[string]
req := newInternalRequest(ctx, 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/restore_repo.go b/modules/private/restore_repo.go
index 66b60d8d12..feb2e1d141 100644
--- a/modules/private/restore_repo.go
+++ b/modules/private/restore_repo.go
@@ -11,8 +11,8 @@ import (
"net/http"
"time"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
- jsoniter "github.com/json-iterator/go"
)
// RestoreParams structure holds a data for restore repository
@@ -30,7 +30,6 @@ func RestoreRepo(ctx context.Context, repoDir, ownerName, repoName string, units
req := newInternalRequest(ctx, reqURL, "POST")
req.SetTimeout(3*time.Second, 0) // since the request will spend much time, don't timeout
req = req.Header("Content-Type", "application/json")
- json := jsoniter.ConfigCompatibleWithStandardLibrary
jsonBytes, _ := json.Marshal(RestoreParams{
RepoDir: repoDir,
OwnerName: ownerName,
diff --git a/modules/private/serv.go b/modules/private/serv.go
index 9643dad679..c378dc6dc7 100644
--- a/modules/private/serv.go
+++ b/modules/private/serv.go
@@ -11,8 +11,8 @@ import (
"net/url"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
- jsoniter "github.com/json-iterator/go"
)
// KeyAndOwner is the response from ServNoCommand
@@ -35,7 +35,6 @@ func ServNoCommand(ctx context.Context, keyID int64) (*models.PublicKey, *models
}
var keyAndOwner KeyAndOwner
- json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.NewDecoder(resp.Body).Decode(&keyAndOwner); err != nil {
return nil, nil, err
}
@@ -91,7 +90,7 @@ func ServCommand(ctx context.Context, keyID int64, ownerName, repoName string, m
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 {