From 2cbaaf2f068246d9babdb508fc24406347888c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Wed, 15 Jan 2025 13:25:55 +0800 Subject: [PATCH] feat: golint --- .idea/.gitignore | 8 -------- .idea/app-cloudep-comment-server.iml | 9 --------- .idea/material_theme_project_new.xml | 10 ---------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ comment.go | 5 +++-- gen_result/pb/comment/comment.pb.go | 5 +++-- gen_result/pb/comment/comment_grpc.pb.go | 1 + internal/server/comment/comment_server.go | 2 +- pkg/domain/entity/comment.go | 1 + pkg/repository/comment.go | 5 +++-- pkg/repository/comment_test.go | 7 ++++--- pkg/usecase/comment.go | 13 ++++++------- pkg/usecase/comment_test.go | 5 +++-- 14 files changed, 25 insertions(+), 60 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/app-cloudep-comment-server.iml delete mode 100644 .idea/material_theme_project_new.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/app-cloudep-comment-server.iml b/.idea/app-cloudep-comment-server.iml deleted file mode 100644 index 5e764c4..0000000 --- a/.idea/app-cloudep-comment-server.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml deleted file mode 100644 index 8859eba..0000000 --- a/.idea/material_theme_project_new.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 3315139..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/comment.go b/comment.go index 30c7f02..15dbe1e 100644 --- a/comment.go +++ b/comment.go @@ -2,7 +2,8 @@ package main import ( "flag" - "fmt" + + "github.com/zeromicro/go-zero/core/logx" "app-cloudep-comment-server/gen_result/pb/comment" "app-cloudep-comment-server/internal/config" @@ -34,6 +35,6 @@ func main() { }) defer s.Stop() - fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) + logx.Infof("Starting rpc server at %s...\n", c.ListenOn) s.Start() } diff --git a/gen_result/pb/comment/comment.pb.go b/gen_result/pb/comment/comment.pb.go index 17289c2..191fc73 100644 --- a/gen_result/pb/comment/comment.pb.go +++ b/gen_result/pb/comment/comment.pb.go @@ -7,10 +7,11 @@ package comment import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" ) const ( diff --git a/gen_result/pb/comment/comment_grpc.pb.go b/gen_result/pb/comment/comment_grpc.pb.go index 3d2109b..f6be997 100644 --- a/gen_result/pb/comment/comment_grpc.pb.go +++ b/gen_result/pb/comment/comment_grpc.pb.go @@ -8,6 +8,7 @@ package comment import ( context "context" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" diff --git a/internal/server/comment/comment_server.go b/internal/server/comment/comment_server.go index 61ff119..eeb8b45 100644 --- a/internal/server/comment/comment_server.go +++ b/internal/server/comment/comment_server.go @@ -8,7 +8,7 @@ import ( "context" "app-cloudep-comment-server/gen_result/pb/comment" - "app-cloudep-comment-server/internal/logic/comment" + commentlogic "app-cloudep-comment-server/internal/logic/comment" "app-cloudep-comment-server/internal/svc" ) diff --git a/pkg/domain/entity/comment.go b/pkg/domain/entity/comment.go index 61bb566..a47b5eb 100644 --- a/pkg/domain/entity/comment.go +++ b/pkg/domain/entity/comment.go @@ -2,6 +2,7 @@ package entity import ( "app-cloudep-comment-server/pkg/domain/comment" + "go.mongodb.org/mongo-driver/bson/primitive" ) diff --git a/pkg/repository/comment.go b/pkg/repository/comment.go index 04d8600..3b7ab7d 100644 --- a/pkg/repository/comment.go +++ b/pkg/repository/comment.go @@ -4,15 +4,16 @@ import ( "app-cloudep-comment-server/pkg/domain" "app-cloudep-comment-server/pkg/domain/entity" "app-cloudep-comment-server/pkg/domain/repository" - mgo "code.30cm.net/digimon/library-go/mongo" "context" "errors" + "time" + + mgo "code.30cm.net/digimon/library-go/mongo" "github.com/zeromicro/go-zero/core/stores/cache" "github.com/zeromicro/go-zero/core/stores/mon" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo/options" - "time" ) type CommentRepositoryParam struct { diff --git a/pkg/repository/comment_test.go b/pkg/repository/comment_test.go index 2467985..2a69bea 100644 --- a/pkg/repository/comment_test.go +++ b/pkg/repository/comment_test.go @@ -3,9 +3,12 @@ package repository import ( "app-cloudep-comment-server/pkg/domain/entity" "app-cloudep-comment-server/pkg/domain/repository" - mgo "code.30cm.net/digimon/library-go/mongo" "context" "fmt" + "testing" + "time" + + mgo "code.30cm.net/digimon/library-go/mongo" "github.com/alicebob/miniredis/v2" "github.com/stretchr/testify/assert" "github.com/zeromicro/go-zero/core/stores/cache" @@ -13,8 +16,6 @@ import ( "github.com/zeromicro/go-zero/core/stores/redis" "go.mongodb.org/mongo-driver/bson/primitive" "google.golang.org/protobuf/proto" - "testing" - "time" ) func SetupTestCommentRepository(db string) (repository.CommentRepository, func(), error) { diff --git a/pkg/usecase/comment.go b/pkg/usecase/comment.go index 1b1ba37..3899d5e 100644 --- a/pkg/usecase/comment.go +++ b/pkg/usecase/comment.go @@ -9,6 +9,7 @@ import ( "context" "encoding/base64" "fmt" + "github.com/golang/snappy" "github.com/zeromicro/go-zero/core/logx" @@ -154,17 +155,14 @@ func (use *CommentUseCase) ListComment(ctx context.Context, req usecase.ListComm } // 批量構建子留言 - replyMap, err := use.buildReplies(ctx, comments) - if err != nil { - return nil, 0, err - } - + replyMap := use.buildReplies(ctx, comments) // 組裝結果 results := make([]*usecase.CommentDocs, 0, len(comments)) for _, item := range comments { decodedMessage, err := decodeMessage(item.Message) if err != nil { logx.WithContext(ctx).Errorf("Failed to decode message: %v", err) + continue } @@ -183,7 +181,7 @@ func (use *CommentUseCase) ListComment(ctx context.Context, req usecase.ListComm return results, total, nil } -func (use *CommentUseCase) buildReplies(ctx context.Context, parentComments []*entity.Comments) (map[string][]*usecase.CommentDocs, error) { +func (use *CommentUseCase) buildReplies(ctx context.Context, parentComments []*entity.Comments) map[string][]*usecase.CommentDocs { // 分組 replyMap := make(map[string][]*usecase.CommentDocs) // 查詢子留言 @@ -202,6 +200,7 @@ func (use *CommentUseCase) buildReplies(ctx context.Context, parentComments []*e decodedMessage, err := decodeMessage(sub.Message) if err != nil { logx.WithContext(ctx).Errorf("Failed to decode message: %v", err) + continue } replyMap[sub.ParentCommentID] = append(replyMap[sub.ParentCommentID], &usecase.CommentDocs{ @@ -216,7 +215,7 @@ func (use *CommentUseCase) buildReplies(ctx context.Context, parentComments []*e } } - return replyMap, nil + return replyMap } func decodeMessage(encodedMessage string) (string, error) { diff --git a/pkg/usecase/comment_test.go b/pkg/usecase/comment_test.go index 31d3c72..1d9cf59 100644 --- a/pkg/usecase/comment_test.go +++ b/pkg/usecase/comment_test.go @@ -8,12 +8,13 @@ import ( "context" "encoding/base64" "errors" + "testing" + "time" + "github.com/golang/snappy" "github.com/stretchr/testify/assert" "go.mongodb.org/mongo-driver/bson/primitive" "go.uber.org/mock/gomock" - "testing" - "time" mockRepo "app-cloudep-comment-server/pkg/mock/repository" err "app-cloudep-comment-server/pkg/repository"