Skip to content

Commit

Permalink
fix:replace the external import sonic to json
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasyRL committed Dec 24, 2024
1 parent 0cb5c50 commit ccf1e13
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
6 changes: 3 additions & 3 deletions api/handler/api/common_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package api

import (
"context"
"encoding/json"
"errors"
"testing"

"github.com/bytedance/mockey"
"github.com/bytedance/sonic"
"github.com/cloudwego/hertz/pkg/common/config"
"github.com/cloudwego/hertz/pkg/common/ut"
"github.com/cloudwego/hertz/pkg/protocol/consts"
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestGetTerm(t *testing.T) {
},
}

data, err := sonic.Marshal(expectedTermInfo)
data, err := json.Marshal(expectedTermInfo)
assert.Nil(t, err)

testCases := []TestCase{
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestGetTermsList(t *testing.T) {
},
}

data, err := sonic.Marshal(expectedTermList)
data, err := json.Marshal(expectedTermList)
assert.Nil(t, err)

testCases := []TestCase{
Expand Down
1 change: 0 additions & 1 deletion cmd/launch_screen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func main() {
if err != nil {
logger.Fatalf("launchScreen: listen addr failed %v", err)
}

svr := launchscreenservice.NewServer(
launch_screen.NewLaunchScreenService(clientSet),
server.WithServerBasicInfo(
Expand Down
4 changes: 2 additions & 2 deletions internal/launch_screen/service/mobile_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ limitations under the License.
package service

import (
"encoding/json"
"errors"
"fmt"
"regexp"

"github.com/bytedance/sonic"
"golang.org/x/sync/errgroup"
"gorm.io/gorm"

Expand Down Expand Up @@ -113,7 +113,7 @@ func (s *LaunchScreenService) getImagesFromMySQL(studentId string, sType int64,
for _, picture := range *imgList {
// 处理JSON
m := make(map[string]string)
if err = sonic.Unmarshal([]byte(picture.Regex), &m); err != nil {
if err = json.Unmarshal([]byte(picture.Regex), &m); err != nil {
return nil, -1, fmt.Errorf("LaunchScreenService.MobileGetImage unmarshal JSON error:%w", err)
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/cache/launch_screen/get_launch_screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ package launch_screen

import (
"context"
"encoding/json"
"fmt"
"strings"

"github.com/bytedance/sonic"

"github.com/west2-online/fzuhelper-server/pkg/constants"
)

Expand All @@ -32,7 +31,7 @@ func (c *CacheLaunchScreen) GetLaunchScreenCache(ctx context.Context, key string
return nil, fmt.Errorf("dal.GetLaunchScreenCache: Get pictureIdList cache failed: %w", err)
}

if err = sonic.Unmarshal([]byte(data), &pictureIdList); err != nil {
if err = json.Unmarshal([]byte(data), &pictureIdList); err != nil {
return nil, fmt.Errorf("dal.GetLaunchScreenCache: Unmarshal pictureIdList failed: %w", err)
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/cache/launch_screen/set_launch_screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ package launch_screen

import (
"context"
"encoding/json"
"fmt"
"strings"

"github.com/bytedance/sonic"

"github.com/west2-online/fzuhelper-server/pkg/constants"
)

func (c *CacheLaunchScreen) SetLaunchScreenCache(ctx context.Context, key string, pictureIdList *[]int64) error {
pictureIdListJson, err := sonic.Marshal(pictureIdList)
pictureIdListJson, err := json.Marshal(pictureIdList)
if err != nil {
return fmt.Errorf("dal.SetLaunchScreenCache: Marshal pictureIdList failed: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/cache/paper/set_file_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package paper

import (
"context"

"github.com/bytedance/sonic"
"encoding/json"

"github.com/west2-online/fzuhelper-server/kitex_gen/model"
"github.com/west2-online/fzuhelper-server/pkg/constants"
Expand All @@ -29,7 +28,7 @@ import (
const TwoDay = 2 * constants.OneDay

func (c *CachePaper) SetFileDirCache(ctx context.Context, key string, dir model.UpYunFileDir) error {
data, err := sonic.Marshal(dir)
data, err := json.Marshal(dir)
if err != nil {
return errno.Errorf(errno.InternalJSONErrorCode, "dal.SetFileDirCache: Unmarshal dir info failed: %v", err)
}
Expand Down

0 comments on commit ccf1e13

Please sign in to comment.