feat: golint

This commit is contained in:
王性驊 2025-01-15 13:25:55 +08:00
parent bf01882628
commit 2cbaaf2f06
14 changed files with 25 additions and 60 deletions

8
.idea/.gitignore vendored
View File

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

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="userId" value="44a3c0f2:19449e817e3:-7fe1" />
</MTProjectMetadataState>
</option>
</component>
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/app-cloudep-comment-server.iml" filepath="$PROJECT_DIR$/.idea/app-cloudep-comment-server.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

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

View File

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

View File

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

View File

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

View File

@ -2,6 +2,7 @@ package entity
import (
"app-cloudep-comment-server/pkg/domain/comment"
"go.mongodb.org/mongo-driver/bson/primitive"
)

View File

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

View File

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

View File

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

View File

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