diff options
Diffstat (limited to 'services')
-rw-r--r-- | services/auth/source/ldap/source.go | 4 | ||||
-rw-r--r-- | services/auth/source/oauth2/source.go | 4 | ||||
-rw-r--r-- | services/auth/source/pam/source.go | 4 | ||||
-rw-r--r-- | services/auth/source/smtp/source.go | 4 | ||||
-rw-r--r-- | services/auth/source/sspi/source.go | 3 | ||||
-rw-r--r-- | services/gitdiff/gitdiff_test.go | 5 | ||||
-rw-r--r-- | services/lfs/locks.go | 6 | ||||
-rw-r--r-- | services/lfs/server.go | 8 | ||||
-rw-r--r-- | services/pull/pull.go | 3 | ||||
-rw-r--r-- | services/webhook/dingtalk.go | 3 | ||||
-rw-r--r-- | services/webhook/discord.go | 5 | ||||
-rw-r--r-- | services/webhook/feishu.go | 3 | ||||
-rw-r--r-- | services/webhook/matrix.go | 6 | ||||
-rw-r--r-- | services/webhook/msteams.go | 3 | ||||
-rw-r--r-- | services/webhook/slack.go | 5 | ||||
-rw-r--r-- | services/webhook/telegram.go | 4 | ||||
-rw-r--r-- | services/webhook/wechatwork.go | 2 |
17 files changed, 24 insertions, 48 deletions
diff --git a/services/auth/source/ldap/source.go b/services/auth/source/ldap/source.go index 87be0117ee..79f118f784 100644 --- a/services/auth/source/ldap/source.go +++ b/services/auth/source/ldap/source.go @@ -8,10 +8,9 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/secret" "code.gitea.io/gitea/modules/setting" - - jsoniter "github.com/json-iterator/go" ) // .____ ________ _____ __________ @@ -79,7 +78,6 @@ func (source *Source) ToDB() ([]byte, error) { return nil, err } source.BindPassword = "" - json := jsoniter.ConfigCompatibleWithStandardLibrary return json.Marshal(source) } diff --git a/services/auth/source/oauth2/source.go b/services/auth/source/oauth2/source.go index e9c49ef90b..40d8973b4b 100644 --- a/services/auth/source/oauth2/source.go +++ b/services/auth/source/oauth2/source.go @@ -6,8 +6,7 @@ package oauth2 import ( "code.gitea.io/gitea/models" - - jsoniter "github.com/json-iterator/go" + "code.gitea.io/gitea/modules/json" ) // ________ _____ __ .__ ________ @@ -37,7 +36,6 @@ func (source *Source) FromDB(bs []byte) error { // ToDB exports an SMTPConfig to a serialized format. func (source *Source) ToDB() ([]byte, error) { - json := jsoniter.ConfigCompatibleWithStandardLibrary return json.Marshal(source) } diff --git a/services/auth/source/pam/source.go b/services/auth/source/pam/source.go index b717ee6fe8..75aa99e45f 100644 --- a/services/auth/source/pam/source.go +++ b/services/auth/source/pam/source.go @@ -6,8 +6,7 @@ package pam import ( "code.gitea.io/gitea/models" - - jsoniter "github.com/json-iterator/go" + "code.gitea.io/gitea/modules/json" ) // __________ _____ _____ @@ -33,7 +32,6 @@ func (source *Source) FromDB(bs []byte) error { // ToDB exports a PAMConfig to a serialized format. func (source *Source) ToDB() ([]byte, error) { - json := jsoniter.ConfigCompatibleWithStandardLibrary return json.Marshal(source) } diff --git a/services/auth/source/smtp/source.go b/services/auth/source/smtp/source.go index 0f948d5381..3d80aea68a 100644 --- a/services/auth/source/smtp/source.go +++ b/services/auth/source/smtp/source.go @@ -6,8 +6,7 @@ package smtp import ( "code.gitea.io/gitea/models" - - jsoniter "github.com/json-iterator/go" + "code.gitea.io/gitea/modules/json" ) // _________ __________________________ @@ -37,7 +36,6 @@ func (source *Source) FromDB(bs []byte) error { // ToDB exports an SMTPConfig to a serialized format. func (source *Source) ToDB() ([]byte, error) { - json := jsoniter.ConfigCompatibleWithStandardLibrary return json.Marshal(source) } diff --git a/services/auth/source/sspi/source.go b/services/auth/source/sspi/source.go index e4be446f30..58cb10de1d 100644 --- a/services/auth/source/sspi/source.go +++ b/services/auth/source/sspi/source.go @@ -6,7 +6,7 @@ package sspi import ( "code.gitea.io/gitea/models" - jsoniter "github.com/json-iterator/go" + "code.gitea.io/gitea/modules/json" ) // _________ ___________________.___ @@ -32,7 +32,6 @@ func (cfg *Source) FromDB(bs []byte) error { // ToDB exports an SSPIConfig to a serialized format. func (cfg *Source) ToDB() ([]byte, error) { - json := jsoniter.ConfigCompatibleWithStandardLibrary return json.Marshal(cfg) } diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go index 2386552efe..94ed1bc407 100644 --- a/services/gitdiff/gitdiff_test.go +++ b/services/gitdiff/gitdiff_test.go @@ -14,8 +14,9 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/highlight" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/setting" - jsoniter "github.com/json-iterator/go" + dmp "github.com/sergi/go-diff/diffmatchpatch" "github.com/stretchr/testify/assert" "gopkg.in/ini.v1" @@ -297,7 +298,7 @@ index 6961180..9ba1a00 100644 t.Errorf("ParsePatch(%q) error = %v, wantErr %v", testcase.name, err, testcase.wantErr) return } - json := jsoniter.ConfigCompatibleWithStandardLibrary + gotMarshaled, _ := json.MarshalIndent(got, "", " ") if got.NumFiles != 1 { t.Errorf("ParsePath(%q) did not receive 1 file:\n%s", testcase.name, string(gotMarshaled)) diff --git a/services/lfs/locks.go b/services/lfs/locks.go index 20ba12e65b..641c1c595b 100644 --- a/services/lfs/locks.go +++ b/services/lfs/locks.go @@ -12,11 +12,11 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" + "code.gitea.io/gitea/modules/json" lfs_module "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" - jsoniter "github.com/json-iterator/go" ) func handleLockListOut(ctx *context.Context, repo *models.Repository, lock *models.LFSLock, err error) { @@ -159,7 +159,7 @@ func PostLockHandler(ctx *context.Context) { var req api.LFSLockRequest bodyReader := ctx.Req.Body defer bodyReader.Close() - json := jsoniter.ConfigCompatibleWithStandardLibrary + dec := json.NewDecoder(bodyReader) if err := dec.Decode(&req); err != nil { log.Warn("Failed to decode lock request as json. Error: %v", err) @@ -293,7 +293,7 @@ func UnLockHandler(ctx *context.Context) { var req api.LFSLockDeleteRequest bodyReader := ctx.Req.Body defer bodyReader.Close() - json := jsoniter.ConfigCompatibleWithStandardLibrary + dec := json.NewDecoder(bodyReader) if err := dec.Decode(&req); err != nil { log.Warn("Failed to decode lock request as json. Error: %v", err) diff --git a/services/lfs/server.go b/services/lfs/server.go index 6b79a3a364..0d357939d5 100644 --- a/services/lfs/server.go +++ b/services/lfs/server.go @@ -17,12 +17,12 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/json" lfs_module "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "github.com/golang-jwt/jwt" - jsoniter "github.com/json-iterator/go" ) // requestContext contain variables from the HTTP request. @@ -243,7 +243,7 @@ func BatchHandler(ctx *context.Context) { ctx.Resp.Header().Set("Content-Type", lfs_module.MediaType) - enc := jsoniter.NewEncoder(ctx.Resp) + enc := json.NewEncoder(ctx.Resp) if err := enc.Encode(respobj); err != nil { log.Error("Failed to encode representation as json. Error: %v", err) } @@ -336,7 +336,7 @@ func VerifyHandler(ctx *context.Context) { func decodeJSON(req *http.Request, v interface{}) error { defer req.Body.Close() - dec := jsoniter.NewDecoder(req.Body) + dec := json.NewDecoder(req.Body) return dec.Decode(v) } @@ -429,7 +429,7 @@ func writeStatusMessage(ctx *context.Context, status int, message string) { er := lfs_module.ErrorResponse{Message: message} - enc := jsoniter.NewEncoder(ctx.Resp) + enc := json.NewEncoder(ctx.Resp) if err := enc.Encode(er); err != nil { log.Error("Failed to encode error response as json. Error: %v", err) } diff --git a/services/pull/pull.go b/services/pull/pull.go index 6b3acd2004..6c108c224f 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -16,11 +16,11 @@ import ( "code.gitea.io/gitea/models" "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/notification" "code.gitea.io/gitea/modules/setting" issue_service "code.gitea.io/gitea/services/issue" - jsoniter "github.com/json-iterator/go" ) // NewPullRequest creates new pull request with labels for repository. @@ -86,7 +86,6 @@ func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int6 data.CommitIDs = append(data.CommitIDs, e.Value.(*git.Commit).ID.String()) } - json := jsoniter.ConfigCompatibleWithStandardLibrary dataJSON, err := json.Marshal(data) if err != nil { return err diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go index 49e161ea57..3296b1114a 100644 --- a/services/webhook/dingtalk.go +++ b/services/webhook/dingtalk.go @@ -10,9 +10,9 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/json" api "code.gitea.io/gitea/modules/structs" - jsoniter "github.com/json-iterator/go" dingtalk "github.com/lunny/dingtalk_webhook" ) @@ -27,7 +27,6 @@ var ( // JSONPayload Marshals the DingtalkPayload to json func (d *DingtalkPayload) JSONPayload() ([]byte, error) { - json := jsoniter.ConfigCompatibleWithStandardLibrary data, err := json.MarshalIndent(d, "", " ") if err != nil { return []byte{}, err diff --git a/services/webhook/discord.go b/services/webhook/discord.go index ea3879f198..9a8f8a27a5 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -12,10 +12,10 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" + "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" - jsoniter "github.com/json-iterator/go" ) type ( @@ -68,7 +68,6 @@ type ( // GetDiscordHook returns discord metadata func GetDiscordHook(w *models.Webhook) *DiscordMeta { s := &DiscordMeta{} - json := jsoniter.ConfigCompatibleWithStandardLibrary if err := json.Unmarshal([]byte(w.Meta), s); err != nil { log.Error("webhook.GetDiscordHook(%d): %v", w.ID, err) } @@ -99,7 +98,6 @@ var ( // JSONPayload Marshals the DiscordPayload to json func (d *DiscordPayload) JSONPayload() ([]byte, error) { - json := jsoniter.ConfigCompatibleWithStandardLibrary data, err := json.MarshalIndent(d, "", " ") if err != nil { return []byte{}, err @@ -250,7 +248,6 @@ func GetDiscordPayload(p api.Payloader, event models.HookEventType, meta string) s := new(DiscordPayload) discord := &DiscordMeta{} - json := jsoniter.ConfigCompatibleWithStandardLibrary if err := json.Unmarshal([]byte(meta), &discord); err != nil { return s, errors.New("GetDiscordPayload meta json:" + err.Error()) } diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go index b280e67759..4428d54f92 100644 --- a/services/webhook/feishu.go +++ b/services/webhook/feishu.go @@ -10,8 +10,8 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/json" api "code.gitea.io/gitea/modules/structs" - jsoniter "github.com/json-iterator/go" ) type ( @@ -37,7 +37,6 @@ func newFeishuTextPayload(text string) *FeishuPayload { // JSONPayload Marshals the FeishuPayload to json func (f *FeishuPayload) JSONPayload() ([]byte, error) { - json := jsoniter.ConfigCompatibleWithStandardLibrary data, err := json.MarshalIndent(f, "", " ") if err != nil { return []byte{}, err diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go index 6fca67ca84..10e0c8fd15 100644 --- a/services/webhook/matrix.go +++ b/services/webhook/matrix.go @@ -15,10 +15,10 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" + "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" - jsoniter "github.com/json-iterator/go" ) const matrixPayloadSizeLimit = 1024 * 64 @@ -39,7 +39,6 @@ var messageTypeText = map[int]string{ // GetMatrixHook returns Matrix metadata func GetMatrixHook(w *models.Webhook) *MatrixMeta { s := &MatrixMeta{} - json := jsoniter.ConfigCompatibleWithStandardLibrary if err := json.Unmarshal([]byte(w.Meta), s); err != nil { log.Error("webhook.GetMatrixHook(%d): %v", w.ID, err) } @@ -78,7 +77,6 @@ type MatrixPayloadSafe struct { // JSONPayload Marshals the MatrixPayloadUnsafe to json func (m *MatrixPayloadUnsafe) JSONPayload() ([]byte, error) { - json := jsoniter.ConfigCompatibleWithStandardLibrary data, err := json.MarshalIndent(m, "", " ") if err != nil { return []byte{}, err @@ -228,7 +226,6 @@ func GetMatrixPayload(p api.Payloader, event models.HookEventType, meta string) s := new(MatrixPayloadUnsafe) matrix := &MatrixMeta{} - json := jsoniter.ConfigCompatibleWithStandardLibrary if err := json.Unmarshal([]byte(meta), &matrix); err != nil { return s, errors.New("GetMatrixPayload meta json:" + err.Error()) } @@ -262,7 +259,6 @@ func getMessageBody(htmlText string) string { // The access_token is removed from t.PayloadContent func getMatrixHookRequest(w *models.Webhook, t *models.HookTask) (*http.Request, error) { payloadunsafe := MatrixPayloadUnsafe{} - json := jsoniter.ConfigCompatibleWithStandardLibrary if err := json.Unmarshal([]byte(t.PayloadContent), &payloadunsafe); err != nil { log.Error("Matrix Hook delivery failed: %v", err) return nil, err diff --git a/services/webhook/msteams.go b/services/webhook/msteams.go index 035dbc1c4c..ed5e659058 100644 --- a/services/webhook/msteams.go +++ b/services/webhook/msteams.go @@ -10,8 +10,8 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/json" api "code.gitea.io/gitea/modules/structs" - jsoniter "github.com/json-iterator/go" ) type ( @@ -57,7 +57,6 @@ type ( // JSONPayload Marshals the MSTeamsPayload to json func (m *MSTeamsPayload) JSONPayload() ([]byte, error) { - json := jsoniter.ConfigCompatibleWithStandardLibrary data, err := json.MarshalIndent(m, "", " ") if err != nil { return []byte{}, err diff --git a/services/webhook/slack.go b/services/webhook/slack.go index f522ca35f2..803b5de0b2 100644 --- a/services/webhook/slack.go +++ b/services/webhook/slack.go @@ -11,10 +11,10 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" + "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" - jsoniter "github.com/json-iterator/go" ) // SlackMeta contains the slack metadata @@ -28,7 +28,6 @@ type SlackMeta struct { // GetSlackHook returns slack metadata func GetSlackHook(w *models.Webhook) *SlackMeta { s := &SlackMeta{} - json := jsoniter.ConfigCompatibleWithStandardLibrary if err := json.Unmarshal([]byte(w.Meta), s); err != nil { log.Error("webhook.GetSlackHook(%d): %v", w.ID, err) } @@ -58,7 +57,6 @@ type SlackAttachment struct { // JSONPayload Marshals the SlackPayload to json func (s *SlackPayload) JSONPayload() ([]byte, error) { - json := jsoniter.ConfigCompatibleWithStandardLibrary data, err := json.MarshalIndent(s, "", " ") if err != nil { return []byte{}, err @@ -279,7 +277,6 @@ func GetSlackPayload(p api.Payloader, event models.HookEventType, meta string) ( s := new(SlackPayload) slack := &SlackMeta{} - json := jsoniter.ConfigCompatibleWithStandardLibrary if err := json.Unmarshal([]byte(meta), &slack); err != nil { return s, errors.New("GetSlackPayload meta json:" + err.Error()) } diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go index 4c4230759d..c5a26f687d 100644 --- a/services/webhook/telegram.go +++ b/services/webhook/telegram.go @@ -10,10 +10,10 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" api "code.gitea.io/gitea/modules/structs" - jsoniter "github.com/json-iterator/go" ) type ( @@ -34,7 +34,6 @@ type ( // GetTelegramHook returns telegram metadata func GetTelegramHook(w *models.Webhook) *TelegramMeta { s := &TelegramMeta{} - json := jsoniter.ConfigCompatibleWithStandardLibrary if err := json.Unmarshal([]byte(w.Meta), s); err != nil { log.Error("webhook.GetTelegramHook(%d): %v", w.ID, err) } @@ -50,7 +49,6 @@ func (t *TelegramPayload) JSONPayload() ([]byte, error) { t.ParseMode = "HTML" t.DisableWebPreview = true t.Message = markup.Sanitize(t.Message) - json := jsoniter.ConfigCompatibleWithStandardLibrary data, err := json.MarshalIndent(t, "", " ") if err != nil { return []byte{}, err diff --git a/services/webhook/wechatwork.go b/services/webhook/wechatwork.go index 1e2d5f4a10..08c77ff2a5 100644 --- a/services/webhook/wechatwork.go +++ b/services/webhook/wechatwork.go @@ -5,12 +5,12 @@ package webhook import ( - "encoding/json" "fmt" "strings" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/json" api "code.gitea.io/gitea/modules/structs" ) |