Skip to content

Commit 610299e

Browse files
committed
Add an abstract json layout to make it's easier to change json library
1 parent e0f9635 commit 610299e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+320
-214
lines changed

build/generate-emoji.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"strings"
2121
"unicode/utf8"
2222

23-
jsoniter "github.com/json-iterator/go"
23+
"code.gitea.io/gitea/modules/json"
2424
)
2525

2626
const (
@@ -51,7 +51,6 @@ func (e Emoji) MarshalJSON() ([]byte, error) {
5151
x.UnicodeVersion = ""
5252
x.Description = ""
5353
x.SkinTones = false
54-
json := jsoniter.ConfigCompatibleWithStandardLibrary
5554
return json.Marshal(x)
5655
}
5756

@@ -103,7 +102,6 @@ func generate() ([]byte, error) {
103102

104103
// unmarshal
105104
var data Gemoji
106-
json := jsoniter.ConfigCompatibleWithStandardLibrary
107105
err = json.Unmarshal(body, &data)
108106
if err != nil {
109107
return nil, err

cmd/dump.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package cmd
77

88
import (
9+
"encoding/json"
910
"fmt"
1011
"io/ioutil"
1112
"os"
@@ -21,7 +22,6 @@ import (
2122
"code.gitea.io/gitea/modules/util"
2223

2324
"gitea.com/go-chi/session"
24-
jsoniter "github.com/json-iterator/go"
2525
archiver "github.com/mholt/archiver/v3"
2626
"github.com/urfave/cli"
2727
)
@@ -306,7 +306,7 @@ func runDump(ctx *cli.Context) error {
306306
var excludes []string
307307
if setting.Cfg.Section("session").Key("PROVIDER").Value() == "file" {
308308
var opts session.Options
309-
json := jsoniter.ConfigCompatibleWithStandardLibrary
309+
310310
if err = json.Unmarshal([]byte(setting.SessionConfig.ProviderConfig), &opts); err != nil {
311311
return err
312312
}

cmd/serv.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package cmd
77

88
import (
9+
"encoding/json"
910
"fmt"
1011
"net/http"
1112
"net/url"
@@ -24,7 +25,6 @@ import (
2425
"code.gitea.io/gitea/services/lfs"
2526

2627
"github.com/golang-jwt/jwt"
27-
jsoniter "github.com/json-iterator/go"
2828
"github.com/kballard/go-shellquote"
2929
"github.com/urfave/cli"
3030
)
@@ -265,7 +265,6 @@ func runServ(c *cli.Context) error {
265265
}
266266
tokenAuthentication.Header["Authorization"] = fmt.Sprintf("Bearer %s", tokenString)
267267

268-
json := jsoniter.ConfigCompatibleWithStandardLibrary
269268
enc := json.NewEncoder(os.Stdout)
270269
err = enc.Encode(tokenAuthentication)
271270
if err != nil {

integrations/api_admin_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
package integrations
66

77
import (
8+
"encoding/json"
89
"fmt"
910
"net/http"
1011
"testing"
1112

1213
"code.gitea.io/gitea/models"
1314
api "code.gitea.io/gitea/modules/structs"
1415

15-
jsoniter "github.com/json-iterator/go"
1616
"github.com/stretchr/testify/assert"
1717
)
1818

@@ -190,7 +190,7 @@ func TestAPIEditUser(t *testing.T) {
190190
resp := session.MakeRequest(t, req, http.StatusUnprocessableEntity)
191191

192192
errMap := make(map[string]interface{})
193-
json := jsoniter.ConfigCompatibleWithStandardLibrary
193+
194194
json.Unmarshal(resp.Body.Bytes(), &errMap)
195195
assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string))
196196

integrations/api_helper_for_declarative_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package integrations
66

77
import (
88
"context"
9+
"encoding/json"
10+
911
"fmt"
1012
"io/ioutil"
1113
"net/http"
@@ -18,7 +20,6 @@ import (
1820
api "code.gitea.io/gitea/modules/structs"
1921
"code.gitea.io/gitea/services/forms"
2022

21-
jsoniter "github.com/json-iterator/go"
2223
"github.com/stretchr/testify/assert"
2324
)
2425

@@ -231,7 +232,6 @@ func doAPICreatePullRequest(ctx APITestContext, owner, repo, baseBranch, headBra
231232
}
232233
resp := ctx.Session.MakeRequest(t, req, expected)
233234

234-
json := jsoniter.ConfigCompatibleWithStandardLibrary
235235
decoder := json.NewDecoder(resp.Body)
236236
pr := api.PullRequest{}
237237
err := decoder.Decode(&pr)
@@ -251,7 +251,6 @@ func doAPIGetPullRequest(ctx APITestContext, owner, repo string, index int64) fu
251251
}
252252
resp := ctx.Session.MakeRequest(t, req, expected)
253253

254-
json := jsoniter.ConfigCompatibleWithStandardLibrary
255254
decoder := json.NewDecoder(resp.Body)
256255
pr := api.PullRequest{}
257256
err := decoder.Decode(&pr)

integrations/api_pull_review_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
package integrations
66

77
import (
8+
"encoding/json"
89
"fmt"
910
"net/http"
1011
"testing"
1112

1213
"code.gitea.io/gitea/models"
1314
api "code.gitea.io/gitea/modules/structs"
14-
jsoniter "github.com/json-iterator/go"
1515
"github.com/stretchr/testify/assert"
1616
)
1717

@@ -189,7 +189,7 @@ func TestAPIPullReview(t *testing.T) {
189189
})
190190
resp = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
191191
errMap := make(map[string]interface{})
192-
json := jsoniter.ConfigCompatibleWithStandardLibrary
192+
193193
json.Unmarshal(resp.Body.Bytes(), &errMap)
194194
assert.EqualValues(t, "review event COMMENT requires a body or a comment", errMap["message"].(string))
195195

integrations/api_repo_lfs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package integrations
66

77
import (
88
"bytes"
9+
"encoding/json"
10+
911
"net/http"
1012
"path"
1113
"strconv"
@@ -16,7 +18,6 @@ import (
1618
"code.gitea.io/gitea/modules/lfs"
1719
"code.gitea.io/gitea/modules/setting"
1820

19-
jsoniter "github.com/json-iterator/go"
2021
"github.com/stretchr/testify/assert"
2122
)
2223

@@ -86,7 +87,6 @@ func TestAPILFSBatch(t *testing.T) {
8687
decodeResponse := func(t *testing.T, b *bytes.Buffer) *lfs.BatchResponse {
8788
var br lfs.BatchResponse
8889

89-
json := jsoniter.ConfigCompatibleWithStandardLibrary
9090
assert.NoError(t, json.Unmarshal(b.Bytes(), &br))
9191
return &br
9292
}

integrations/create_no_session_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package integrations
66

77
import (
8+
"encoding/json"
89
"io/ioutil"
910
"net/http"
1011
"net/http/httptest"
@@ -17,7 +18,6 @@ import (
1718
"code.gitea.io/gitea/routers"
1819

1920
"gitea.com/go-chi/session"
20-
jsoniter "github.com/json-iterator/go"
2121
"github.com/stretchr/testify/assert"
2222
)
2323

@@ -63,7 +63,6 @@ func TestSessionFileCreation(t *testing.T) {
6363

6464
var config session.Options
6565

66-
json := jsoniter.ConfigCompatibleWithStandardLibrary
6766
err := json.Unmarshal([]byte(oldSessionConfig), &config)
6867
assert.NoError(t, err)
6968

integrations/integration_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"bytes"
99
"context"
1010
"database/sql"
11+
"encoding/json"
12+
1113
"fmt"
1214
"hash"
1315
"hash/fnv"
@@ -37,7 +39,6 @@ import (
3739
"code.gitea.io/gitea/routers"
3840

3941
"github.com/PuerkitoBio/goquery"
40-
jsoniter "github.com/json-iterator/go"
4142
"github.com/stretchr/testify/assert"
4243
)
4344

@@ -416,7 +417,6 @@ func NewRequestWithValues(t testing.TB, method, urlStr string, values map[string
416417
func NewRequestWithJSON(t testing.TB, method, urlStr string, v interface{}) *http.Request {
417418
t.Helper()
418419

419-
json := jsoniter.ConfigCompatibleWithStandardLibrary
420420
jsonBytes, err := json.Marshal(v)
421421
assert.NoError(t, err)
422422
req := NewRequestWithBody(t, method, urlStr, bytes.NewBuffer(jsonBytes))
@@ -508,7 +508,6 @@ func logUnexpectedResponse(t testing.TB, recorder *httptest.ResponseRecorder) {
508508
func DecodeJSON(t testing.TB, resp *httptest.ResponseRecorder, v interface{}) {
509509
t.Helper()
510510

511-
json := jsoniter.ConfigCompatibleWithStandardLibrary
512511
decoder := json.NewDecoder(resp.Body)
513512
assert.NoError(t, decoder.Decode(v))
514513
}

integrations/oauth_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ package integrations
66

77
import (
88
"bytes"
9+
"encoding/json"
10+
911
"io/ioutil"
1012
"testing"
1113

1214
"code.gitea.io/gitea/modules/setting"
1315

14-
jsoniter "github.com/json-iterator/go"
1516
"github.com/stretchr/testify/assert"
1617
)
1718

@@ -71,7 +72,6 @@ func TestAccessTokenExchange(t *testing.T) {
7172
}
7273
parsed := new(response)
7374

74-
json := jsoniter.ConfigCompatibleWithStandardLibrary
7575
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
7676
assert.True(t, len(parsed.AccessToken) > 10)
7777
assert.True(t, len(parsed.RefreshToken) > 10)
@@ -96,7 +96,6 @@ func TestAccessTokenExchangeWithoutPKCE(t *testing.T) {
9696
}
9797
parsed := new(response)
9898

99-
json := jsoniter.ConfigCompatibleWithStandardLibrary
10099
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
101100
assert.True(t, len(parsed.AccessToken) > 10)
102101
assert.True(t, len(parsed.RefreshToken) > 10)
@@ -186,7 +185,6 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
186185
}
187186
parsed := new(response)
188187

189-
json := jsoniter.ConfigCompatibleWithStandardLibrary
190188
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
191189
assert.True(t, len(parsed.AccessToken) > 10)
192190
assert.True(t, len(parsed.RefreshToken) > 10)
@@ -230,7 +228,6 @@ func TestRefreshTokenInvalidation(t *testing.T) {
230228
}
231229
parsed := new(response)
232230

233-
json := jsoniter.ConfigCompatibleWithStandardLibrary
234231
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
235232

236233
// test without invalidation

integrations/repo_commits_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package integrations
66

77
import (
8+
"encoding/json"
89
"net/http"
910
"net/http/httptest"
1011
"path"
@@ -13,7 +14,6 @@ import (
1314
"code.gitea.io/gitea/modules/setting"
1415
api "code.gitea.io/gitea/modules/structs"
1516

16-
jsoniter "github.com/json-iterator/go"
1717
"github.com/stretchr/testify/assert"
1818
)
1919

@@ -86,7 +86,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
8686
}
8787

8888
func testRepoCommitsWithStatus(t *testing.T, resp, respOne *httptest.ResponseRecorder, state string) {
89-
json := jsoniter.ConfigCompatibleWithStandardLibrary
89+
9090
var statuses []*api.CommitStatus
9191
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &statuses))
9292
var status api.CombinedStatus

integrations/testlogger.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package integrations
66

77
import (
88
"context"
9+
"encoding/json"
10+
911
"fmt"
1012
"os"
1113
"runtime"
@@ -16,7 +18,6 @@ import (
1618

1719
"code.gitea.io/gitea/modules/log"
1820
"code.gitea.io/gitea/modules/queue"
19-
jsoniter "github.com/json-iterator/go"
2021
)
2122

2223
var (
@@ -158,7 +159,7 @@ func NewTestLogger() log.LoggerProvider {
158159
// Init inits connection writer with json config.
159160
// json config only need key "level".
160161
func (log *TestLogger) Init(config string) error {
161-
json := jsoniter.ConfigCompatibleWithStandardLibrary
162+
162163
err := json.Unmarshal([]byte(config), log)
163164
if err != nil {
164165
return err

models/issue_comment.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ package models
88

99
import (
1010
"container/list"
11+
"encoding/json"
12+
1113
"fmt"
1214
"regexp"
1315
"strconv"
@@ -21,7 +23,6 @@ import (
2123
"code.gitea.io/gitea/modules/references"
2224
"code.gitea.io/gitea/modules/structs"
2325
"code.gitea.io/gitea/modules/timeutil"
24-
jsoniter "github.com/json-iterator/go"
2526

2627
"xorm.io/builder"
2728
"xorm.io/xorm"
@@ -654,7 +655,6 @@ func (c *Comment) LoadPushCommits() (err error) {
654655

655656
var data PushActionContent
656657

657-
json := jsoniter.ConfigCompatibleWithStandardLibrary
658658
err = json.Unmarshal([]byte(c.Content), &data)
659659
if err != nil {
660660
return
@@ -1249,7 +1249,6 @@ func CreatePushPullComment(pusher *User, pr *PullRequest, oldCommitID, newCommit
12491249

12501250
ops.Issue = pr.Issue
12511251

1252-
json := jsoniter.ConfigCompatibleWithStandardLibrary
12531252
dataJSON, err := json.Marshal(data)
12541253
if err != nil {
12551254
return nil, err

models/migrations/testlogger_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package migrations
66

77
import (
88
"context"
9+
"encoding/json"
10+
911
"fmt"
1012
"os"
1113
"runtime"
@@ -16,7 +18,6 @@ import (
1618

1719
"code.gitea.io/gitea/modules/log"
1820
"code.gitea.io/gitea/modules/queue"
19-
jsoniter "github.com/json-iterator/go"
2021
)
2122

2223
var (
@@ -158,7 +159,7 @@ func NewTestLogger() log.LoggerProvider {
158159
// Init inits connection writer with json config.
159160
// json config only need key "level".
160161
func (log *TestLogger) Init(config string) error {
161-
json := jsoniter.ConfigCompatibleWithStandardLibrary
162+
162163
err := json.Unmarshal([]byte(config), log)
163164
if err != nil {
164165
return err

0 commit comments

Comments
 (0)