diff --git a/go.mod b/go.mod index b0b7b976..331a99d5 100644 --- a/go.mod +++ b/go.mod @@ -18,8 +18,10 @@ require ( github.com/go-playground/validator/v10 v10.10.1 // indirect github.com/go-redis/redis/v8 v8.11.4 github.com/go-resty/resty/v2 v2.7.0 + github.com/goccy/go-json v0.9.7 github.com/gofrs/uuid v4.0.0+incompatible github.com/google/go-cmp v0.5.7 // indirect + github.com/json-iterator/go v1.1.12 github.com/minio/minio-go/v7 v7.0.27 github.com/sirupsen/logrus v1.8.1 github.com/smartwalle/alipay/v3 v3.1.7 diff --git a/go.sum b/go.sum index 904a427a..fe11f231 100644 --- a/go.sum +++ b/go.sum @@ -273,6 +273,8 @@ github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfC github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= +github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= diff --git a/internal/conf/logger.go b/internal/conf/logger.go index 31724a6d..16a2b8f7 100644 --- a/internal/conf/logger.go +++ b/internal/conf/logger.go @@ -1,11 +1,11 @@ package conf import ( - "encoding/json" "fmt" "io" "time" + "github.com/rocboss/paopao-ce/pkg/json" "github.com/sirupsen/logrus" "gopkg.in/natefinch/lumberjack.v2" "gopkg.in/resty.v1" diff --git a/internal/dao/user.go b/internal/dao/user.go index ce07f5c9..7292ec1d 100644 --- a/internal/dao/user.go +++ b/internal/dao/user.go @@ -1,7 +1,6 @@ package dao import ( - "encoding/json" "errors" "fmt" "math/rand" @@ -12,6 +11,7 @@ import ( "github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/model" + "github.com/rocboss/paopao-ce/pkg/json" "gopkg.in/resty.v1" ) diff --git a/internal/service/post.go b/internal/service/post.go index 0f3cf28f..e5960074 100644 --- a/internal/service/post.go +++ b/internal/service/post.go @@ -1,7 +1,6 @@ package service import ( - "encoding/json" "errors" "fmt" "math" @@ -13,6 +12,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/model" "github.com/rocboss/paopao-ce/pkg/errcode" + "github.com/rocboss/paopao-ce/pkg/json" "github.com/rocboss/paopao-ce/pkg/util" "github.com/rocboss/paopao-ce/pkg/zinc" "github.com/sirupsen/logrus" diff --git a/pkg/json/go_json.go b/pkg/json/go_json.go new file mode 100644 index 00000000..23f71726 --- /dev/null +++ b/pkg/json/go_json.go @@ -0,0 +1,23 @@ +// Copyright 2017 Bo-Yi Wu. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +//go:build go_json +// +build go_json + +package json + +import json "github.com/goccy/go-json" + +var ( + // Marshal is exported by gin/json package. + Marshal = json.Marshal + // Unmarshal is exported by gin/json package. + Unmarshal = json.Unmarshal + // MarshalIndent is exported by gin/json package. + MarshalIndent = json.MarshalIndent + // NewDecoder is exported by gin/json package. + NewDecoder = json.NewDecoder + // NewEncoder is exported by gin/json package. + NewEncoder = json.NewEncoder +) diff --git a/pkg/json/json.go b/pkg/json/json.go new file mode 100644 index 00000000..a26d7db2 --- /dev/null +++ b/pkg/json/json.go @@ -0,0 +1,23 @@ +// Copyright 2017 Bo-Yi Wu. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +//go:build !jsoniter && !go_json +// +build !jsoniter,!go_json + +package json + +import "encoding/json" + +var ( + // Marshal is exported by gin/json package. + Marshal = json.Marshal + // Unmarshal is exported by gin/json package. + Unmarshal = json.Unmarshal + // MarshalIndent is exported by gin/json package. + MarshalIndent = json.MarshalIndent + // NewDecoder is exported by gin/json package. + NewDecoder = json.NewDecoder + // NewEncoder is exported by gin/json package. + NewEncoder = json.NewEncoder +) diff --git a/pkg/json/jsoniter.go b/pkg/json/jsoniter.go new file mode 100644 index 00000000..853b1a90 --- /dev/null +++ b/pkg/json/jsoniter.go @@ -0,0 +1,24 @@ +// Copyright 2017 Bo-Yi Wu. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +//go:build jsoniter +// +build jsoniter + +package json + +import jsoniter "github.com/json-iterator/go" + +var ( + json = jsoniter.ConfigCompatibleWithStandardLibrary + // Marshal is exported by gin/json package. + Marshal = json.Marshal + // Unmarshal is exported by gin/json package. + Unmarshal = json.Unmarshal + // MarshalIndent is exported by gin/json package. + MarshalIndent = json.MarshalIndent + // NewDecoder is exported by gin/json package. + NewDecoder = json.NewDecoder + // NewEncoder is exported by gin/json package. + NewEncoder = json.NewEncoder +) diff --git a/pkg/zinc/zinc.go b/pkg/zinc/zinc.go index 8e73221d..4ea31051 100644 --- a/pkg/zinc/zinc.go +++ b/pkg/zinc/zinc.go @@ -1,7 +1,6 @@ package zinc import ( - "encoding/json" "errors" "fmt" "net/http" @@ -9,6 +8,7 @@ import ( "github.com/go-resty/resty/v2" "github.com/rocboss/paopao-ce/internal/conf" + "github.com/rocboss/paopao-ce/pkg/json" ) type ZincClient struct {