diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-07-25 00:03:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-24 18:03:58 +0200 |
commit | 9f31f3aa8ac4f6bfc8390c9ae63b2a387b414c88 (patch) | |
tree | 6f27dc68a35d1f9d806c632e36f0edc8543184ea /routers | |
parent | e0f9635c0691cb67f0fcbb758cabba801d9fc51b (diff) | |
download | gitea-9f31f3aa8ac4f6bfc8390c9ae63b2a387b414c88.tar.gz gitea-9f31f3aa8ac4f6bfc8390c9ae63b2a387b414c88.zip |
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
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/utils/hook.go | 4 | ||||
-rw-r--r-- | routers/private/mail.go | 4 | ||||
-rw-r--r-- | routers/private/manager.go | 3 | ||||
-rw-r--r-- | routers/private/restore_repo.go | 3 | ||||
-rw-r--r-- | routers/web/admin/admin.go | 3 | ||||
-rw-r--r-- | routers/web/events/events.go | 3 | ||||
-rw-r--r-- | routers/web/repo/editor.go | 3 | ||||
-rw-r--r-- | routers/web/repo/webhook.go | 12 | ||||
-rw-r--r-- | routers/web/user/home.go | 3 | ||||
-rw-r--r-- | routers/web/user/oauth.go | 4 | ||||
-rw-r--r-- | routers/web/user/task.go | 3 |
11 files changed, 15 insertions, 30 deletions
diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go index 5f2be65a29..a257260cad 100644 --- a/routers/api/v1/utils/hook.go +++ b/routers/api/v1/utils/hook.go @@ -12,11 +12,11 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" + "code.gitea.io/gitea/modules/json" api "code.gitea.io/gitea/modules/structs" "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,7 +147,6 @@ 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"], @@ -222,7 +221,6 @@ 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"], diff --git a/routers/private/mail.go b/routers/private/mail.go index d7bd5155f6..6b9100159a 100644 --- a/routers/private/mail.go +++ b/routers/private/mail.go @@ -11,11 +11,11 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "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,7 +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, private.Response{ diff --git a/routers/private/manager.go b/routers/private/manager.go index 7d010f3f81..2b4cfb8ef4 100644 --- a/routers/private/manager.go +++ b/routers/private/manager.go @@ -10,12 +10,12 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/graceful" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/private" "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,7 +130,6 @@ 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) diff --git a/routers/private/restore_repo.go b/routers/private/restore_repo.go index 36d17dd95c..87d60537cd 100644 --- a/routers/private/restore_repo.go +++ b/routers/private/restore_repo.go @@ -9,14 +9,13 @@ import ( "net/http" myCtx "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/migrations" "code.gitea.io/gitea/modules/private" - jsoniter "github.com/json-iterator/go" ) // RestoreRepo restore a repository from data func RestoreRepo(ctx *myCtx.PrivateContext) { - json := jsoniter.ConfigCompatibleWithStandardLibrary bs, err := ioutil.ReadAll(ctx.Req.Body) if err != nil { ctx.JSON(http.StatusInternalServerError, private.Response{ diff --git a/routers/web/admin/admin.go b/routers/web/admin/admin.go index c2d94ab9c9..125bef9b53 100644 --- a/routers/web/admin/admin.go +++ b/routers/web/admin/admin.go @@ -20,6 +20,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/cron" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/queue" @@ -28,7 +29,6 @@ import ( "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/mailer" - jsoniter "github.com/json-iterator/go" "gitea.com/go-chi/session" ) @@ -275,7 +275,6 @@ 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) } diff --git a/routers/web/events/events.go b/routers/web/events/events.go index f9cc274851..a630d9c224 100644 --- a/routers/web/events/events.go +++ b/routers/web/events/events.go @@ -13,10 +13,10 @@ import ( "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/eventsource" "code.gitea.io/gitea/modules/graceful" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/routers/web/user" - jsoniter "github.com/json-iterator/go" ) // Events listens for events @@ -103,7 +103,6 @@ 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) diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index 0f978c7b01..792258da84 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/charset" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/repofiles" repo_module "code.gitea.io/gitea/modules/repository" @@ -26,7 +27,6 @@ import ( "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/utils" "code.gitea.io/gitea/services/forms" - jsoniter "github.com/json-iterator/go" ) const ( @@ -165,7 +165,6 @@ 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) } diff --git a/routers/web/repo/webhook.go b/routers/web/repo/webhook.go index 30fa98f809..946801cb76 100644 --- a/routers/web/repo/webhook.go +++ b/routers/web/repo/webhook.go @@ -17,13 +17,13 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/webhook" - jsoniter "github.com/json-iterator/go" ) const ( @@ -306,7 +306,6 @@ func DiscordHooksNewPost(ctx *context.Context) { return } - json := jsoniter.ConfigCompatibleWithStandardLibrary meta, err := json.Marshal(&webhook.DiscordMeta{ Username: form.Username, IconURL: form.IconURL, @@ -402,7 +401,6 @@ func TelegramHooksNewPost(ctx *context.Context) { return } - json := jsoniter.ConfigCompatibleWithStandardLibrary meta, err := json.Marshal(&webhook.TelegramMeta{ BotToken: form.BotToken, ChatID: form.ChatID, @@ -455,7 +453,6 @@ func MatrixHooksNewPost(ctx *context.Context) { return } - json := jsoniter.ConfigCompatibleWithStandardLibrary meta, err := json.Marshal(&webhook.MatrixMeta{ HomeserverURL: form.HomeserverURL, Room: form.RoomID, @@ -560,7 +557,6 @@ func SlackHooksNewPost(ctx *context.Context) { return } - json := jsoniter.ConfigCompatibleWithStandardLibrary meta, err := json.Marshal(&webhook.SlackMeta{ Channel: strings.TrimSpace(form.Channel), Username: form.Username, @@ -848,7 +844,6 @@ func SlackHooksEditPost(ctx *context.Context) { return } - json := jsoniter.ConfigCompatibleWithStandardLibrary meta, err := json.Marshal(&webhook.SlackMeta{ Channel: strings.TrimSpace(form.Channel), Username: form.Username, @@ -894,7 +889,6 @@ func DiscordHooksEditPost(ctx *context.Context) { return } - json := jsoniter.ConfigCompatibleWithStandardLibrary meta, err := json.Marshal(&webhook.DiscordMeta{ Username: form.Username, IconURL: form.IconURL, @@ -970,7 +964,7 @@ func TelegramHooksEditPost(ctx *context.Context) { ctx.HTML(http.StatusOK, orCtx.NewTemplate) return } - json := jsoniter.ConfigCompatibleWithStandardLibrary + meta, err := json.Marshal(&webhook.TelegramMeta{ BotToken: form.BotToken, ChatID: form.ChatID, @@ -1012,7 +1006,7 @@ func MatrixHooksEditPost(ctx *context.Context) { ctx.HTML(http.StatusOK, orCtx.NewTemplate) return } - json := jsoniter.ConfigCompatibleWithStandardLibrary + meta, err := json.Marshal(&webhook.MatrixMeta{ HomeserverURL: form.HomeserverURL, Room: form.RoomID, diff --git a/routers/web/user/home.go b/routers/web/user/home.go index d3fc36c730..fcf5295c9e 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -18,6 +18,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" issue_indexer "code.gitea.io/gitea/modules/indexer/issues" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" @@ -26,7 +27,6 @@ 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" @@ -703,7 +703,6 @@ func buildIssueOverview(ctx *context.Context, unitType models.UnitType) { } // Convert []int64 to string - json := jsoniter.ConfigCompatibleWithStandardLibrary reposParam, _ := json.Marshal(repoIDs) ctx.Data["ReposParam"] = string(reposParam) diff --git a/routers/web/user/oauth.go b/routers/web/user/oauth.go index 07fff8370c..18fc943483 100644 --- a/routers/web/user/oauth.go +++ b/routers/web/user/oauth.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" @@ -25,7 +26,6 @@ import ( "gitea.com/go-chi/binding" "github.com/golang-jwt/jwt" - jsoniter "github.com/json-iterator/go" ) const ( @@ -507,7 +507,7 @@ func OIDCKeys(ctx *context.Context) { } ctx.Resp.Header().Set("Content-Type", "application/json") - enc := jsoniter.NewEncoder(ctx.Resp) + enc := json.NewEncoder(ctx.Resp) if err := enc.Encode(jwks); err != nil { log.Error("Failed to encode representation as json. Error: %v", err) } diff --git a/routers/web/user/task.go b/routers/web/user/task.go index 8e7b66ef95..c71d435233 100644 --- a/routers/web/user/task.go +++ b/routers/web/user/task.go @@ -9,7 +9,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" - jsoniter "github.com/json-iterator/go" + "code.gitea.io/gitea/modules/json" ) // TaskStatus returns task's status @@ -26,7 +26,6 @@ func TaskStatus(ctx *context.Context) { if task.Message != "" && task.Message[0] == '{' { // assume message is actually a translatable string - json := jsoniter.ConfigCompatibleWithStandardLibrary var translatableMessage models.TranslatableMessage if err := json.Unmarshal([]byte(message), &translatableMessage); err != nil { translatableMessage = models.TranslatableMessage{ |