diff options
author | zeripath <art27@cantab.net> | 2021-03-01 21:08:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-01 22:08:10 +0100 |
commit | f0e15250b9e322cc7731ba026d12387c2b549a42 (patch) | |
tree | f13d46119077ba924d620ef172b91daa315bda0a /modules/structs/hook.go | |
parent | 59fd641d1fb021e35aea7f9f4a1916cc11ef5c51 (diff) | |
download | gitea-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 'modules/structs/hook.go')
-rw-r--r-- | modules/structs/hook.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/modules/structs/hook.go b/modules/structs/hook.go index 45ae94f985..693820b57d 100644 --- a/modules/structs/hook.go +++ b/modules/structs/hook.go @@ -6,10 +6,11 @@ package structs import ( - "encoding/json" "errors" "strings" "time" + + jsoniter "github.com/json-iterator/go" ) var ( @@ -138,12 +139,14 @@ func (p *CreatePayload) SetSecret(secret string) { // JSONPayload return payload information func (p *CreatePayload) JSONPayload() ([]byte, error) { + json := jsoniter.ConfigCompatibleWithStandardLibrary return json.MarshalIndent(p, "", " ") } // ParseCreateHook parses create event hook content. func ParseCreateHook(raw []byte) (*CreatePayload, error) { hook := new(CreatePayload) + json := jsoniter.ConfigCompatibleWithStandardLibrary if err := json.Unmarshal(raw, hook); err != nil { return nil, err } @@ -193,6 +196,7 @@ func (p *DeletePayload) SetSecret(secret string) { // JSONPayload implements Payload func (p *DeletePayload) JSONPayload() ([]byte, error) { + json := jsoniter.ConfigCompatibleWithStandardLibrary return json.MarshalIndent(p, "", " ") } @@ -218,6 +222,7 @@ func (p *ForkPayload) SetSecret(secret string) { // JSONPayload implements Payload func (p *ForkPayload) JSONPayload() ([]byte, error) { + json := jsoniter.ConfigCompatibleWithStandardLibrary return json.MarshalIndent(p, "", " ") } @@ -250,6 +255,7 @@ func (p *IssueCommentPayload) SetSecret(secret string) { // JSONPayload implements Payload func (p *IssueCommentPayload) JSONPayload() ([]byte, error) { + json := jsoniter.ConfigCompatibleWithStandardLibrary return json.MarshalIndent(p, "", " ") } @@ -286,6 +292,7 @@ func (p *ReleasePayload) SetSecret(secret string) { // JSONPayload implements Payload func (p *ReleasePayload) JSONPayload() ([]byte, error) { + json := jsoniter.ConfigCompatibleWithStandardLibrary return json.MarshalIndent(p, "", " ") } @@ -317,12 +324,14 @@ func (p *PushPayload) SetSecret(secret string) { // JSONPayload FIXME func (p *PushPayload) JSONPayload() ([]byte, error) { + json := jsoniter.ConfigCompatibleWithStandardLibrary return json.MarshalIndent(p, "", " ") } // ParsePushHook parses push event hook content. func ParsePushHook(raw []byte) (*PushPayload, error) { hook := new(PushPayload) + json := jsoniter.ConfigCompatibleWithStandardLibrary if err := json.Unmarshal(raw, hook); err != nil { return nil, err } @@ -396,6 +405,7 @@ func (p *IssuePayload) SetSecret(secret string) { // JSONPayload encodes the IssuePayload to JSON, with an indentation of two spaces. func (p *IssuePayload) JSONPayload() ([]byte, error) { + json := jsoniter.ConfigCompatibleWithStandardLibrary return json.MarshalIndent(p, "", " ") } @@ -437,6 +447,7 @@ func (p *PullRequestPayload) SetSecret(secret string) { // JSONPayload FIXME func (p *PullRequestPayload) JSONPayload() ([]byte, error) { + json := jsoniter.ConfigCompatibleWithStandardLibrary return json.MarshalIndent(p, "", " ") } @@ -479,5 +490,6 @@ func (p *RepositoryPayload) SetSecret(secret string) { // JSONPayload JSON representation of the payload func (p *RepositoryPayload) JSONPayload() ([]byte, error) { + json := jsoniter.ConfigCompatibleWithStandardLibrary return json.MarshalIndent(p, "", " ") } |