diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-07-25 00:03:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-24 18:03:58 +0200 |
commit | 9f31f3aa8ac4f6bfc8390c9ae63b2a387b414c88 (patch) | |
tree | 6f27dc68a35d1f9d806c632e36f0edc8543184ea /services/webhook | |
parent | e0f9635c0691cb67f0fcbb758cabba801d9fc51b (diff) | |
download | gitea-9f31f3aa8ac4f6bfc8390c9ae63b2a387b414c88.tar.gz gitea-9f31f3aa8ac4f6bfc8390c9ae63b2a387b414c88.zip |
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
Diffstat (limited to 'services/webhook')
-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 |
8 files changed, 8 insertions, 23 deletions
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" ) |