aboutsummaryrefslogtreecommitdiffstats
path: root/services/webhook/matrix.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-03-01 21:08:10 +0000
committerGitHub <noreply@github.com>2021-03-01 22:08:10 +0100
commitf0e15250b9e322cc7731ba026d12387c2b549a42 (patch)
treef13d46119077ba924d620ef172b91daa315bda0a /services/webhook/matrix.go
parent59fd641d1fb021e35aea7f9f4a1916cc11ef5c51 (diff)
downloadgitea-f0e15250b9e322cc7731ba026d12387c2b549a42.tar.gz
gitea-f0e15250b9e322cc7731ba026d12387c2b549a42.zip
Migrate to use jsoniter instead of encoding/json (#14841)
* Migrate to use jsoniter * fix tests * update gitea.com/go-chi/binding Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'services/webhook/matrix.go')
-rw-r--r--services/webhook/matrix.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go
index 063147198a..1658dd4b44 100644
--- a/services/webhook/matrix.go
+++ b/services/webhook/matrix.go
@@ -6,7 +6,6 @@ package webhook
import (
"crypto/sha1"
- "encoding/json"
"errors"
"fmt"
"html"
@@ -19,6 +18,7 @@ import (
"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,6 +39,7 @@ 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)
}
@@ -80,6 +81,7 @@ func (m *MatrixPayloadUnsafe) SetSecret(_ string) {}
// 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
@@ -229,6 +231,7 @@ 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,6 +265,7 @@ func getMessageBody(htmlText string) string {
// The access_token is removed from t.PayloadContent
func getMatrixHookRequest(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