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:
parent
59fd641d1f
commit
f0e15250b9
77 changed files with 264 additions and 82 deletions
|
@ -6,7 +6,6 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -28,6 +27,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/mailer"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
||||
"gitea.com/go-chi/session"
|
||||
)
|
||||
|
@ -274,6 +274,7 @@ func Config(ctx *context.Context) {
|
|||
sessionCfg := setting.SessionConfig
|
||||
if sessionCfg.Provider == "VirtualSession" {
|
||||
var realSession session.Options
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
if err := json.Unmarshal([]byte(sessionCfg.ProviderConfig), &realSession); err != nil {
|
||||
log.Error("Unable to unmarshall session config for virtualed provider config: %s\nError: %v", sessionCfg.ProviderConfig, err)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -17,6 +16,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/routers/utils"
|
||||
"code.gitea.io/gitea/services/webhook"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
// GetOrgHook get an organization's webhook. If there is an error, write to
|
||||
|
@ -147,6 +147,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
|
|||
return nil, false
|
||||
}
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
meta, err := json.Marshal(&webhook.SlackMeta{
|
||||
Channel: strings.TrimSpace(channel),
|
||||
Username: form.Config["username"],
|
||||
|
@ -221,6 +222,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *models.Webho
|
|||
|
||||
if w.Type == models.SLACK {
|
||||
if channel, ok := form.Config["channel"]; ok {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
meta, err := json.Marshal(&webhook.SlackMeta{
|
||||
Channel: channel,
|
||||
Username: form.Config["username"],
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package events
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
@ -17,6 +16,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/routers/user"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
// Events listens for events
|
||||
|
@ -92,6 +92,7 @@ loop:
|
|||
log.Error("Unable to APIFormat stopwatches: %v", err)
|
||||
continue
|
||||
}
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
dataBs, err := json.Marshal(apiSWs)
|
||||
if err != nil {
|
||||
log.Error("Unable to marshal stopwatches: %v", err)
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package private
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
@ -16,6 +15,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/private"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/services/mailer"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
// SendEmail pushes messages to mail queue
|
||||
|
@ -32,6 +32,7 @@ func SendEmail(ctx *context.PrivateContext) {
|
|||
var mail private.Email
|
||||
rd := ctx.Req.Body
|
||||
defer rd.Close()
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
if err := json.NewDecoder(rd).Decode(&mail); err != nil {
|
||||
log.Error("%v", err)
|
||||
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package private
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
|
@ -16,6 +15,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/queue"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
// FlushQueues flushes all the Queues
|
||||
|
@ -130,6 +130,7 @@ func AddLogger(ctx *context.PrivateContext) {
|
|||
}
|
||||
|
||||
bufferLen := setting.Cfg.Section("log").Key("BUFFER_LEN").MustInt64(10000)
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
byteConfig, err := json.Marshal(opts.Config)
|
||||
if err != nil {
|
||||
log.Error("Failed to marshal log configuration: %v %v", opts.Config, err)
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
|
@ -25,6 +24,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/utils"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -158,6 +158,7 @@ func GetEditorConfig(ctx *context.Context, treePath string) string {
|
|||
if err == nil {
|
||||
def, err := ec.GetDefinitionForFilename(treePath)
|
||||
if err == nil {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
jsonStr, _ := json.Marshal(def)
|
||||
return string(jsonStr)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
|
@ -23,6 +22,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/webhook"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -305,6 +305,7 @@ func DiscordHooksNewPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
meta, err := json.Marshal(&webhook.DiscordMeta{
|
||||
Username: form.Username,
|
||||
IconURL: form.IconURL,
|
||||
|
@ -400,6 +401,7 @@ func TelegramHooksNewPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
meta, err := json.Marshal(&webhook.TelegramMeta{
|
||||
BotToken: form.BotToken,
|
||||
ChatID: form.ChatID,
|
||||
|
@ -452,6 +454,7 @@ func MatrixHooksNewPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
meta, err := json.Marshal(&webhook.MatrixMeta{
|
||||
HomeserverURL: form.HomeserverURL,
|
||||
Room: form.RoomID,
|
||||
|
@ -556,6 +559,7 @@ func SlackHooksNewPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
meta, err := json.Marshal(&webhook.SlackMeta{
|
||||
Channel: strings.TrimSpace(form.Channel),
|
||||
Username: form.Username,
|
||||
|
@ -799,6 +803,7 @@ func SlackHooksEditPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
meta, err := json.Marshal(&webhook.SlackMeta{
|
||||
Channel: strings.TrimSpace(form.Channel),
|
||||
Username: form.Username,
|
||||
|
@ -844,6 +849,7 @@ func DiscordHooksEditPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
meta, err := json.Marshal(&webhook.DiscordMeta{
|
||||
Username: form.Username,
|
||||
IconURL: form.IconURL,
|
||||
|
@ -919,6 +925,7 @@ func TelegramHooksEditPost(ctx *context.Context) {
|
|||
ctx.HTML(200, orCtx.NewTemplate)
|
||||
return
|
||||
}
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
meta, err := json.Marshal(&webhook.TelegramMeta{
|
||||
BotToken: form.BotToken,
|
||||
ChatID: form.ChatID,
|
||||
|
@ -960,6 +967,7 @@ func MatrixHooksEditPost(ctx *context.Context) {
|
|||
ctx.HTML(200, orCtx.NewTemplate)
|
||||
return
|
||||
}
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
meta, err := json.Marshal(&webhook.MatrixMeta{
|
||||
HomeserverURL: form.HomeserverURL,
|
||||
Room: form.RoomID,
|
||||
|
|
|
@ -7,7 +7,6 @@ package user
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
|
@ -25,6 +24,7 @@ import (
|
|||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/keybase/go-crypto/openpgp"
|
||||
"github.com/keybase/go-crypto/openpgp/armor"
|
||||
"xorm.io/builder"
|
||||
|
@ -691,6 +691,7 @@ func buildIssueOverview(ctx *context.Context, unitType models.UnitType) {
|
|||
}
|
||||
|
||||
// Convert []int64 to string
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
reposParam, _ := json.Marshal(repoIDs)
|
||||
|
||||
ctx.Data["ReposParam"] = string(reposParam)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue