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:
2021-07-25 00:03:58 +08:00
committed by GitHub
parent e0f9635c06
commit 9f31f3aa8a
93 changed files with 272 additions and 264 deletions

View File

@ -20,7 +20,7 @@ import (
"strings"
"unicode/utf8"
jsoniter "github.com/json-iterator/go"
"code.gitea.io/gitea/modules/json"
)
const (
@ -51,7 +51,6 @@ func (e Emoji) MarshalJSON() ([]byte, error) {
x.UnicodeVersion = ""
x.Description = ""
x.SkinTones = false
json := jsoniter.ConfigCompatibleWithStandardLibrary
return json.Marshal(x)
}
@ -103,7 +102,6 @@ func generate() ([]byte, error) {
// unmarshal
var data Gemoji
json := jsoniter.ConfigCompatibleWithStandardLibrary
err = json.Unmarshal(body, &data)
if err != nil {
return nil, err

View File

@ -15,13 +15,13 @@ import (
"time"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/util"
"gitea.com/go-chi/session"
jsoniter "github.com/json-iterator/go"
archiver "github.com/mholt/archiver/v3"
"github.com/urfave/cli"
)
@ -306,7 +306,6 @@ func runDump(ctx *cli.Context) error {
var excludes []string
if setting.Cfg.Section("session").Key("PROVIDER").Value() == "file" {
var opts session.Options
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err = json.Unmarshal([]byte(setting.SessionConfig.ProviderConfig), &opts); err != nil {
return err
}

View File

@ -17,6 +17,7 @@ import (
"time"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/pprof"
"code.gitea.io/gitea/modules/private"
@ -24,7 +25,6 @@ import (
"code.gitea.io/gitea/services/lfs"
"github.com/golang-jwt/jwt"
jsoniter "github.com/json-iterator/go"
"github.com/kballard/go-shellquote"
"github.com/urfave/cli"
)
@ -265,7 +265,6 @@ func runServ(c *cli.Context) error {
}
tokenAuthentication.Header["Authorization"] = fmt.Sprintf("Bearer %s", tokenString)
json := jsoniter.ConfigCompatibleWithStandardLibrary
enc := json.NewEncoder(os.Stdout)
err = enc.Encode(tokenAuthentication)
if err != nil {

View File

@ -10,9 +10,9 @@ import (
"testing"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/json"
api "code.gitea.io/gitea/modules/structs"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@ -190,7 +190,6 @@ func TestAPIEditUser(t *testing.T) {
resp := session.MakeRequest(t, req, http.StatusUnprocessableEntity)
errMap := make(map[string]interface{})
json := jsoniter.ConfigCompatibleWithStandardLibrary
json.Unmarshal(resp.Body.Bytes(), &errMap)
assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string))

View File

@ -14,11 +14,11 @@ import (
"time"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/queue"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/services/forms"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@ -231,7 +231,6 @@ func doAPICreatePullRequest(ctx APITestContext, owner, repo, baseBranch, headBra
}
resp := ctx.Session.MakeRequest(t, req, expected)
json := jsoniter.ConfigCompatibleWithStandardLibrary
decoder := json.NewDecoder(resp.Body)
pr := api.PullRequest{}
err := decoder.Decode(&pr)
@ -251,7 +250,6 @@ func doAPIGetPullRequest(ctx APITestContext, owner, repo string, index int64) fu
}
resp := ctx.Session.MakeRequest(t, req, expected)
json := jsoniter.ConfigCompatibleWithStandardLibrary
decoder := json.NewDecoder(resp.Body)
pr := api.PullRequest{}
err := decoder.Decode(&pr)

View File

@ -10,8 +10,9 @@ import (
"testing"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/json"
api "code.gitea.io/gitea/modules/structs"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@ -189,7 +190,6 @@ func TestAPIPullReview(t *testing.T) {
})
resp = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
errMap := make(map[string]interface{})
json := jsoniter.ConfigCompatibleWithStandardLibrary
json.Unmarshal(resp.Body.Bytes(), &errMap)
assert.EqualValues(t, "review event COMMENT requires a body or a comment", errMap["message"].(string))

View File

@ -13,10 +13,10 @@ import (
"testing"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/setting"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@ -86,7 +86,6 @@ func TestAPILFSBatch(t *testing.T) {
decodeResponse := func(t *testing.T, b *bytes.Buffer) *lfs.BatchResponse {
var br lfs.BatchResponse
json := jsoniter.ConfigCompatibleWithStandardLibrary
assert.NoError(t, json.Unmarshal(b.Bytes(), &br))
return &br
}

View File

@ -12,12 +12,12 @@ import (
"path/filepath"
"testing"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers"
"gitea.com/go-chi/session"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@ -63,7 +63,6 @@ func TestSessionFileCreation(t *testing.T) {
var config session.Options
json := jsoniter.ConfigCompatibleWithStandardLibrary
err := json.Unmarshal([]byte(oldSessionConfig), &config)
assert.NoError(t, err)

View File

@ -28,6 +28,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/queue"
"code.gitea.io/gitea/modules/setting"
@ -37,7 +38,6 @@ import (
"code.gitea.io/gitea/routers"
"github.com/PuerkitoBio/goquery"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@ -416,7 +416,6 @@ func NewRequestWithValues(t testing.TB, method, urlStr string, values map[string
func NewRequestWithJSON(t testing.TB, method, urlStr string, v interface{}) *http.Request {
t.Helper()
json := jsoniter.ConfigCompatibleWithStandardLibrary
jsonBytes, err := json.Marshal(v)
assert.NoError(t, err)
req := NewRequestWithBody(t, method, urlStr, bytes.NewBuffer(jsonBytes))
@ -508,7 +507,6 @@ func logUnexpectedResponse(t testing.TB, recorder *httptest.ResponseRecorder) {
func DecodeJSON(t testing.TB, resp *httptest.ResponseRecorder, v interface{}) {
t.Helper()
json := jsoniter.ConfigCompatibleWithStandardLibrary
decoder := json.NewDecoder(resp.Body)
assert.NoError(t, decoder.Decode(v))
}

View File

@ -14,11 +14,11 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers/web"
jsoniter "github.com/json-iterator/go"
gzipp "github.com/klauspost/compress/gzip"
"github.com/stretchr/testify/assert"
)
@ -206,7 +206,7 @@ func TestGetLFSRange(t *testing.T) {
assert.Equal(t, tt.out, resp.Body.String())
} else {
var er lfs.ErrorResponse
err := jsoniter.Unmarshal(resp.Body.Bytes(), &er)
err := json.Unmarshal(resp.Body.Bytes(), &er)
assert.NoError(t, err)
assert.Equal(t, tt.out, er.Message)
}

View File

@ -9,9 +9,9 @@ import (
"io/ioutil"
"testing"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@ -71,7 +71,6 @@ func TestAccessTokenExchange(t *testing.T) {
}
parsed := new(response)
json := jsoniter.ConfigCompatibleWithStandardLibrary
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
assert.True(t, len(parsed.AccessToken) > 10)
assert.True(t, len(parsed.RefreshToken) > 10)
@ -96,7 +95,6 @@ func TestAccessTokenExchangeWithoutPKCE(t *testing.T) {
}
parsed := new(response)
json := jsoniter.ConfigCompatibleWithStandardLibrary
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
assert.True(t, len(parsed.AccessToken) > 10)
assert.True(t, len(parsed.RefreshToken) > 10)
@ -186,7 +184,6 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
}
parsed := new(response)
json := jsoniter.ConfigCompatibleWithStandardLibrary
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
assert.True(t, len(parsed.AccessToken) > 10)
assert.True(t, len(parsed.RefreshToken) > 10)
@ -230,7 +227,6 @@ func TestRefreshTokenInvalidation(t *testing.T) {
}
parsed := new(response)
json := jsoniter.ConfigCompatibleWithStandardLibrary
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
// test without invalidation

View File

@ -10,10 +10,10 @@ import (
"path"
"testing"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@ -86,7 +86,6 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
}
func testRepoCommitsWithStatus(t *testing.T, resp, respOne *httptest.ResponseRecorder, state string) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
var statuses []*api.CommitStatus
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &statuses))
var status api.CombinedStatus

View File

@ -14,9 +14,9 @@ import (
"testing"
"time"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/queue"
jsoniter "github.com/json-iterator/go"
)
var (
@ -158,7 +158,6 @@ func NewTestLogger() log.LoggerProvider {
// Init inits connection writer with json config.
// json config only need key "level".
func (log *TestLogger) Init(config string) error {
json := jsoniter.ConfigCompatibleWithStandardLibrary
err := json.Unmarshal([]byte(config), log)
if err != nil {
return err

View File

@ -7,7 +7,7 @@ package models
import (
"encoding/binary"
jsoniter "github.com/json-iterator/go"
"code.gitea.io/gitea/modules/json"
)
func keysInt64(m map[int64]struct{}) []int64 {
@ -37,7 +37,6 @@ func valuesUser(m map[int64]*User) []*User {
// JSONUnmarshalHandleDoubleEncode - due to a bug in xorm (see https://gitea.com/xorm/xorm/pulls/1957) - it's
// possible that a Blob may be double encoded or gain an unwanted prefix of 0xff 0xfe.
func JSONUnmarshalHandleDoubleEncode(bs []byte, v interface{}) error {
json := jsoniter.ConfigCompatibleWithStandardLibrary
err := json.Unmarshal(bs, v)
if err != nil {
ok := true

View File

@ -15,13 +15,13 @@ import (
"unicode/utf8"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/references"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
jsoniter "github.com/json-iterator/go"
"xorm.io/builder"
"xorm.io/xorm"
@ -654,7 +654,6 @@ func (c *Comment) LoadPushCommits() (err error) {
var data PushActionContent
json := jsoniter.ConfigCompatibleWithStandardLibrary
err = json.Unmarshal([]byte(c.Content), &data)
if err != nil {
return
@ -1249,7 +1248,6 @@ func CreatePushPullComment(pusher *User, pr *PullRequest, oldCommitID, newCommit
ops.Issue = pr.Issue
json := jsoniter.ConfigCompatibleWithStandardLibrary
dataJSON, err := json.Marshal(data)
if err != nil {
return nil, err

View File

@ -14,9 +14,9 @@ import (
"testing"
"time"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/queue"
jsoniter "github.com/json-iterator/go"
)
var (
@ -158,7 +158,6 @@ func NewTestLogger() log.LoggerProvider {
// Init inits connection writer with json config.
// json config only need key "level".
func (log *TestLogger) Init(config string) error {
json := jsoniter.ConfigCompatibleWithStandardLibrary
err := json.Unmarshal([]byte(config), log)
if err != nil {
return err

View File

@ -5,8 +5,8 @@
package migrations
import (
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
jsoniter "github.com/json-iterator/go"
"xorm.io/xorm"
)
@ -70,7 +70,6 @@ func expandWebhooks(x *xorm.Engine) error {
for _, res := range results {
var events HookEvent
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err = json.Unmarshal([]byte(res.Events), &events); err != nil {
return err
}

View File

@ -5,9 +5,9 @@
package migrations
import (
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/util"
jsoniter "github.com/json-iterator/go"
"xorm.io/builder"
"xorm.io/xorm"
)
@ -105,7 +105,6 @@ func removeCredentials(payload string) (string, error) {
}
var opts MigrateOptions
json := jsoniter.ConfigCompatibleWithStandardLibrary
err := json.Unmarshal([]byte(payload), &opts)
if err != nil {
return "", err

View File

@ -8,13 +8,13 @@ import (
"encoding/binary"
"fmt"
jsoniter "github.com/json-iterator/go"
"code.gitea.io/gitea/modules/json"
"xorm.io/xorm"
)
func unwrapLDAPSourceCfg(x *xorm.Engine) error {
jsonUnmarshalHandleDoubleEncode := func(bs []byte, v interface{}) error {
json := jsoniter.ConfigCompatibleWithStandardLibrary
err := json.Unmarshal(bs, v)
if err != nil {
ok := true
@ -84,7 +84,7 @@ func unwrapLDAPSourceCfg(x *xorm.Engine) error {
return fmt.Errorf("failed to unmarshal %s: %w", string(source.Cfg), err)
}
if wrapped.Source != nil && len(wrapped.Source) > 0 {
bs, err := jsoniter.Marshal(wrapped.Source)
bs, err := json.Marshal(wrapped.Source)
if err != nil {
return err
}

View File

@ -7,7 +7,8 @@ package migrations
import (
"testing"
jsoniter "github.com/json-iterator/go"
"code.gitea.io/gitea/modules/json"
"github.com/stretchr/testify/assert"
)
@ -65,12 +66,12 @@ func Test_unwrapLDAPSourceCfg(t *testing.T) {
converted := map[string]interface{}{}
expected := map[string]interface{}{}
if err := jsoniter.Unmarshal([]byte(source.Cfg), &converted); err != nil {
if err := json.Unmarshal([]byte(source.Cfg), &converted); err != nil {
assert.NoError(t, err)
return
}
if err := jsoniter.Unmarshal([]byte(source.Expected), &expected); err != nil {
if err := json.Unmarshal([]byte(source.Expected), &expected); err != nil {
assert.NoError(t, err)
return
}

View File

@ -7,9 +7,9 @@ package models
import (
"fmt"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/timeutil"
jsoniter "github.com/json-iterator/go"
"xorm.io/xorm"
"xorm.io/xorm/convert"
)
@ -33,7 +33,6 @@ func (cfg *UnitConfig) FromDB(bs []byte) error {
// ToDB exports a UnitConfig to a serialized format.
func (cfg *UnitConfig) ToDB() ([]byte, error) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
return json.Marshal(cfg)
}
@ -49,7 +48,6 @@ func (cfg *ExternalWikiConfig) FromDB(bs []byte) error {
// ToDB exports a ExternalWikiConfig to a serialized format.
func (cfg *ExternalWikiConfig) ToDB() ([]byte, error) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
return json.Marshal(cfg)
}
@ -67,7 +65,6 @@ func (cfg *ExternalTrackerConfig) FromDB(bs []byte) error {
// ToDB exports a ExternalTrackerConfig to a serialized format.
func (cfg *ExternalTrackerConfig) ToDB() ([]byte, error) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
return json.Marshal(cfg)
}
@ -85,7 +82,6 @@ func (cfg *IssuesConfig) FromDB(bs []byte) error {
// ToDB exports a IssuesConfig to a serialized format.
func (cfg *IssuesConfig) ToDB() ([]byte, error) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
return json.Marshal(cfg)
}
@ -109,7 +105,6 @@ func (cfg *PullRequestsConfig) FromDB(bs []byte) error {
// ToDB exports a PullRequestsConfig to a serialized format.
func (cfg *PullRequestsConfig) ToDB() ([]byte, error) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
return json.Marshal(cfg)
}

View File

@ -7,13 +7,13 @@ package models
import (
"fmt"
"code.gitea.io/gitea/modules/json"
migration "code.gitea.io/gitea/modules/migrations/base"
"code.gitea.io/gitea/modules/secret"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
jsoniter "github.com/json-iterator/go"
"xorm.io/builder"
)
@ -114,7 +114,6 @@ func (task *Task) UpdateCols(cols ...string) error {
func (task *Task) MigrateConfig() (*migration.MigrateOptions, error) {
if task.Type == structs.TaskTypeMigrateRepo {
var opts migration.MigrateOptions
json := jsoniter.ConfigCompatibleWithStandardLibrary
err := json.Unmarshal([]byte(task.PayloadContent), &opts)
if err != nil {
return nil, err
@ -190,7 +189,6 @@ func GetMigratingTaskByID(id, doerID int64) (*Task, *migration.MigrateOptions, e
}
var opts migration.MigrateOptions
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal([]byte(task.PayloadContent), &opts); err != nil {
return nil, nil, err
}
@ -244,7 +242,6 @@ func FinishMigrateTask(task *Task) error {
conf.AuthPasswordEncrypted = ""
conf.AuthTokenEncrypted = ""
conf.CloneAddrEncrypted = ""
json := jsoniter.ConfigCompatibleWithStandardLibrary
confBytes, err := json.Marshal(conf)
if err != nil {
return err

View File

@ -8,7 +8,8 @@ import (
"fmt"
"testing"
jsoniter "github.com/json-iterator/go"
"code.gitea.io/gitea/modules/json"
"github.com/stretchr/testify/assert"
)
@ -68,7 +69,6 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
assert.Equal(t, tc.CountResult, contributions, fmt.Sprintf("testcase %d", i))
// Test JSON rendering
json := jsoniter.ConfigCompatibleWithStandardLibrary
jsonData, err := json.Marshal(heatmap)
assert.NoError(t, err)
assert.Equal(t, tc.JSONResult, string(jsonData))

View File

@ -11,13 +11,13 @@ import (
"strings"
"time"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
gouuid "github.com/google/uuid"
jsoniter "github.com/json-iterator/go"
)
// HookContentType is the content type of a web hook
@ -160,8 +160,6 @@ type Webhook struct {
// AfterLoad updates the webhook object upon setting a column
func (w *Webhook) AfterLoad() {
w.HookEvent = &HookEvent{}
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal([]byte(w.Events), w.HookEvent); err != nil {
log.Error("Unmarshal[%d]: %v", w.ID, err)
}
@ -174,7 +172,6 @@ func (w *Webhook) History(page int) ([]*HookTask, error) {
// UpdateEvent handles conversion from HookEvent to Events.
func (w *Webhook) UpdateEvent() error {
json := jsoniter.ConfigCompatibleWithStandardLibrary
data, err := json.Marshal(w.HookEvent)
w.Events = string(data)
return err
@ -687,7 +684,6 @@ func (t *HookTask) AfterLoad() {
}
t.RequestInfo = &HookRequest{}
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal([]byte(t.RequestContent), t.RequestInfo); err != nil {
log.Error("Unmarshal RequestContent[%d]: %v", t.ID, err)
}
@ -701,7 +697,6 @@ func (t *HookTask) AfterLoad() {
}
func (t *HookTask) simpleMarshalJSON(v interface{}) string {
json := jsoniter.ConfigCompatibleWithStandardLibrary
p, err := json.Marshal(v)
if err != nil {
log.Error("Marshal [%d]: %v", t.ID, err)

View File

@ -9,9 +9,9 @@ import (
"testing"
"time"
"code.gitea.io/gitea/modules/json"
api "code.gitea.io/gitea/modules/structs"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@ -58,7 +58,6 @@ func TestWebhook_UpdateEvent(t *testing.T) {
assert.NoError(t, webhook.UpdateEvent())
assert.NotEmpty(t, webhook.Events)
actualHookEvent := &HookEvent{}
json := jsoniter.ConfigCompatibleWithStandardLibrary
assert.NoError(t, json.Unmarshal([]byte(webhook.Events), actualHookEvent))
assert.Equal(t, *hookEvent, *actualHookEvent)
}

View File

@ -9,9 +9,10 @@ import (
"sync"
"time"
"code.gitea.io/gitea/modules/json"
mc "gitea.com/go-chi/cache"
lru "github.com/hashicorp/golang-lru"
jsoniter "github.com/json-iterator/go"
)
// TwoQueueCache represents a LRU 2Q cache adapter implementation
@ -177,7 +178,6 @@ func (c *TwoQueueCache) StartAndGC(opts mc.Options) error {
size, err = strconv.Atoi(opts.AdapterConfig)
}
if err != nil {
json := jsoniter.ConfigCompatibleWithStandardLibrary
if !json.Valid([]byte(opts.AdapterConfig)) {
return err
}

View File

@ -23,6 +23,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
mc "code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/templates"
@ -34,7 +35,6 @@ import (
"gitea.com/go-chi/cache"
"gitea.com/go-chi/session"
"github.com/go-chi/chi"
jsoniter "github.com/json-iterator/go"
"github.com/unknwon/com"
"github.com/unknwon/i18n"
"github.com/unrolled/render"
@ -408,7 +408,6 @@ func (ctx *Context) Error(status int, contents ...string) {
func (ctx *Context) JSON(status int, content interface{}) {
ctx.Resp.Header().Set("Content-Type", "application/json;charset=utf-8")
ctx.Resp.WriteHeader(status)
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.NewEncoder(ctx.Resp).Encode(content); err != nil {
ctx.ServerError("Render JSON failed", err)
}

View File

@ -11,7 +11,7 @@ import (
"strings"
"time"
jsoniter "github.com/json-iterator/go"
"code.gitea.io/gitea/modules/json"
)
func wrapNewlines(w io.Writer, prefix []byte, value []byte) (sum int64, err error) {
@ -80,7 +80,6 @@ func (e *Event) WriteTo(w io.Writer) (int64, error) {
data = []byte(v)
default:
var err error
json := jsoniter.ConfigCompatibleWithStandardLibrary
data, err = json.Marshal(e.Data)
if err != nil {
return sum, err
@ -91,7 +90,6 @@ func (e *Event) WriteTo(w io.Writer) (int64, error) {
if err != nil {
return sum, err
}
}
n, err = wrapNewlines(w, []byte("id: "), []byte(e.ID))

View File

@ -24,7 +24,7 @@ import (
"sync"
"time"
jsoniter "github.com/json-iterator/go"
"code.gitea.io/gitea/modules/json"
)
var defaultSetting = Settings{false, "GiteaServer", 60 * time.Second, 60 * time.Second, nil, nil, nil, false}
@ -443,7 +443,6 @@ func (r *Request) ToJSON(v interface{}) error {
if err != nil {
return err
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
err = json.Unmarshal(data, v)
return err
}

View File

@ -18,13 +18,13 @@ import (
"code.gitea.io/gitea/modules/analyze"
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/typesniffer"
"github.com/go-enry/go-enry/v2"
jsoniter "github.com/json-iterator/go"
"github.com/olivere/elastic/v7"
)
@ -321,7 +321,6 @@ func convertResult(searchResult *elastic.SearchResult, kw string, pageSize int)
repoID, fileName := parseIndexerID(hit.Id)
var res = make(map[string]interface{})
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(hit.Source, &res); err != nil {
return 0, nil, nil, err
}

Some files were not shown because too many files have changed in this diff Show More