mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
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
This commit is contained in:
parent
e0f9635c06
commit
9f31f3aa8a
93 changed files with 272 additions and 264 deletions
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue