1
0
Fork 0
forked from forgejo/forgejo

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>
This commit is contained in:
zeripath 2021-03-01 21:08:10 +00:00 committed by GitHub
parent 59fd641d1f
commit f0e15250b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
77 changed files with 264 additions and 82 deletions

View file

@ -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, "", " ")
}