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:
parent
e0f9635c06
commit
9f31f3aa8a
93 changed files with 272 additions and 264 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue