From 082e16fb427065728eda1401efa4567bce2aa733 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 2 Jul 2018 09:39:25 +0900 Subject: [PATCH] Use jsoniter to improve performance --- auth/facebook.go | 4 ++-- auth/google.go | 4 ++-- layout/layout.go | 6 +++--- utils/ToJSON.go | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/auth/facebook.go b/auth/facebook.go index 58ba2b2e..a1a4a674 100644 --- a/auth/facebook.go +++ b/auth/facebook.go @@ -2,7 +2,6 @@ package auth import ( "context" - "encoding/json" "errors" "io/ioutil" "net/http" @@ -11,6 +10,7 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/utils" + jsoniter "github.com/json-iterator/go" "golang.org/x/oauth2" "golang.org/x/oauth2/facebook" ) @@ -88,7 +88,7 @@ func InstallFacebookAuth(app *aero.Application) { // Construct a FacebookUser object fbUser := FacebookUser{} - err = json.Unmarshal(body, &fbUser) + err = jsoniter.Unmarshal(body, &fbUser) if err != nil { return ctx.Error(http.StatusBadRequest, "Failed parsing user data (JSON)", err) diff --git a/auth/google.go b/auth/google.go index 6d95ee84..87d2f47e 100644 --- a/auth/google.go +++ b/auth/google.go @@ -2,7 +2,6 @@ package auth import ( "context" - "encoding/json" "errors" "io/ioutil" "net/http" @@ -11,6 +10,7 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/utils" + jsoniter "github.com/json-iterator/go" "golang.org/x/oauth2" "golang.org/x/oauth2/google" ) @@ -94,7 +94,7 @@ func InstallGoogleAuth(app *aero.Application) { // Construct a GoogleUser object var googleUser GoogleUser - err = json.Unmarshal(data, &googleUser) + err = jsoniter.Unmarshal(data, &googleUser) if err != nil { return ctx.Error(http.StatusBadRequest, "Failed parsing user data (JSON)", err) diff --git a/layout/layout.go b/layout/layout.go index 98af3bb3..0b54d753 100644 --- a/layout/layout.go +++ b/layout/layout.go @@ -1,7 +1,6 @@ package fullpage import ( - "encoding/json" "io/ioutil" "sort" @@ -9,6 +8,7 @@ import ( "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/utils" + jsoniter "github.com/json-iterator/go" ) var organization map[string]interface{} @@ -17,8 +17,8 @@ var organizationString string func init() { // Load structured data organizationBytes, _ := ioutil.ReadFile("organization.json") - json.Unmarshal(organizationBytes, &organization) - organizationBytes, _ = json.Marshal(organization) + jsoniter.Unmarshal(organizationBytes, &organization) + organizationBytes, _ = jsoniter.Marshal(organization) organizationString = string(organizationBytes) } diff --git a/utils/ToJSON.go b/utils/ToJSON.go index 614b4465..2d861acf 100644 --- a/utils/ToJSON.go +++ b/utils/ToJSON.go @@ -1,9 +1,9 @@ package utils -import "encoding/json" +import jsoniter "github.com/json-iterator/go" // ToJSON converts an object to a JSON string, ignoring errors. func ToJSON(v interface{}) string { - str, _ := json.Marshal(v) + str, _ := jsoniter.Marshal(v) return string(str) }