Use jsoniter to improve performance

This commit is contained in:
Eduard Urbach 2018-07-02 09:39:25 +09:00
parent bb1ce79d95
commit 082e16fb42
4 changed files with 9 additions and 9 deletions

View File

@ -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)

View File

@ -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)

View File

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

View File

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