1
0
Fork 0
forked from forgejo/forgejo

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:
Lunny Xiao 2021-07-25 00:03:58 +08:00 committed by GitHub
parent e0f9635c06
commit 9f31f3aa8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
93 changed files with 272 additions and 264 deletions

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
}