feat: golint
This commit is contained in:
		
							parent
							
								
									bf01882628
								
							
						
					
					
						commit
						2cbaaf2f06
					
				|  | @ -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 |  | ||||||
|  | @ -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> |  | ||||||
|  | @ -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> |  | ||||||
|  | @ -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> |  | ||||||
|  | @ -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> |  | ||||||
|  | @ -2,7 +2,8 @@ package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"flag" | 	"flag" | ||||||
| 	"fmt" | 
 | ||||||
|  | 	"github.com/zeromicro/go-zero/core/logx" | ||||||
| 
 | 
 | ||||||
| 	"app-cloudep-comment-server/gen_result/pb/comment" | 	"app-cloudep-comment-server/gen_result/pb/comment" | ||||||
| 	"app-cloudep-comment-server/internal/config" | 	"app-cloudep-comment-server/internal/config" | ||||||
|  | @ -34,6 +35,6 @@ func main() { | ||||||
| 	}) | 	}) | ||||||
| 	defer s.Stop() | 	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() | 	s.Start() | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,10 +7,11 @@ | ||||||
| package comment | package comment | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	protoreflect "google.golang.org/protobuf/reflect/protoreflect" |  | ||||||
| 	protoimpl "google.golang.org/protobuf/runtime/protoimpl" |  | ||||||
| 	reflect "reflect" | 	reflect "reflect" | ||||||
| 	sync "sync" | 	sync "sync" | ||||||
|  | 
 | ||||||
|  | 	protoreflect "google.golang.org/protobuf/reflect/protoreflect" | ||||||
|  | 	protoimpl "google.golang.org/protobuf/runtime/protoimpl" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
|  |  | ||||||
|  | @ -8,6 +8,7 @@ package comment | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	context "context" | 	context "context" | ||||||
|  | 
 | ||||||
| 	grpc "google.golang.org/grpc" | 	grpc "google.golang.org/grpc" | ||||||
| 	codes "google.golang.org/grpc/codes" | 	codes "google.golang.org/grpc/codes" | ||||||
| 	status "google.golang.org/grpc/status" | 	status "google.golang.org/grpc/status" | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 
 | 
 | ||||||
| 	"app-cloudep-comment-server/gen_result/pb/comment" | 	"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" | 	"app-cloudep-comment-server/internal/svc" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ package entity | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"app-cloudep-comment-server/pkg/domain/comment" | 	"app-cloudep-comment-server/pkg/domain/comment" | ||||||
|  | 
 | ||||||
| 	"go.mongodb.org/mongo-driver/bson/primitive" | 	"go.mongodb.org/mongo-driver/bson/primitive" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -4,15 +4,16 @@ import ( | ||||||
| 	"app-cloudep-comment-server/pkg/domain" | 	"app-cloudep-comment-server/pkg/domain" | ||||||
| 	"app-cloudep-comment-server/pkg/domain/entity" | 	"app-cloudep-comment-server/pkg/domain/entity" | ||||||
| 	"app-cloudep-comment-server/pkg/domain/repository" | 	"app-cloudep-comment-server/pkg/domain/repository" | ||||||
| 	mgo "code.30cm.net/digimon/library-go/mongo" |  | ||||||
| 	"context" | 	"context" | ||||||
| 	"errors" | 	"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/cache" | ||||||
| 	"github.com/zeromicro/go-zero/core/stores/mon" | 	"github.com/zeromicro/go-zero/core/stores/mon" | ||||||
| 	"go.mongodb.org/mongo-driver/bson" | 	"go.mongodb.org/mongo-driver/bson" | ||||||
| 	"go.mongodb.org/mongo-driver/bson/primitive" | 	"go.mongodb.org/mongo-driver/bson/primitive" | ||||||
| 	"go.mongodb.org/mongo-driver/mongo/options" | 	"go.mongodb.org/mongo-driver/mongo/options" | ||||||
| 	"time" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type CommentRepositoryParam struct { | type CommentRepositoryParam struct { | ||||||
|  |  | ||||||
|  | @ -3,9 +3,12 @@ package repository | ||||||
| import ( | import ( | ||||||
| 	"app-cloudep-comment-server/pkg/domain/entity" | 	"app-cloudep-comment-server/pkg/domain/entity" | ||||||
| 	"app-cloudep-comment-server/pkg/domain/repository" | 	"app-cloudep-comment-server/pkg/domain/repository" | ||||||
| 	mgo "code.30cm.net/digimon/library-go/mongo" |  | ||||||
| 	"context" | 	"context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 	"testing" | ||||||
|  | 	"time" | ||||||
|  | 
 | ||||||
|  | 	mgo "code.30cm.net/digimon/library-go/mongo" | ||||||
| 	"github.com/alicebob/miniredis/v2" | 	"github.com/alicebob/miniredis/v2" | ||||||
| 	"github.com/stretchr/testify/assert" | 	"github.com/stretchr/testify/assert" | ||||||
| 	"github.com/zeromicro/go-zero/core/stores/cache" | 	"github.com/zeromicro/go-zero/core/stores/cache" | ||||||
|  | @ -13,8 +16,6 @@ import ( | ||||||
| 	"github.com/zeromicro/go-zero/core/stores/redis" | 	"github.com/zeromicro/go-zero/core/stores/redis" | ||||||
| 	"go.mongodb.org/mongo-driver/bson/primitive" | 	"go.mongodb.org/mongo-driver/bson/primitive" | ||||||
| 	"google.golang.org/protobuf/proto" | 	"google.golang.org/protobuf/proto" | ||||||
| 	"testing" |  | ||||||
| 	"time" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func SetupTestCommentRepository(db string) (repository.CommentRepository, func(), error) { | func SetupTestCommentRepository(db string) (repository.CommentRepository, func(), error) { | ||||||
|  |  | ||||||
|  | @ -9,6 +9,7 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"encoding/base64" | 	"encoding/base64" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 
 | ||||||
| 	"github.com/golang/snappy" | 	"github.com/golang/snappy" | ||||||
| 	"github.com/zeromicro/go-zero/core/logx" | 	"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) | 	replyMap := use.buildReplies(ctx, comments) | ||||||
| 	if err != nil { |  | ||||||
| 		return nil, 0, err |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// 組裝結果
 | 	// 組裝結果
 | ||||||
| 	results := make([]*usecase.CommentDocs, 0, len(comments)) | 	results := make([]*usecase.CommentDocs, 0, len(comments)) | ||||||
| 	for _, item := range comments { | 	for _, item := range comments { | ||||||
| 		decodedMessage, err := decodeMessage(item.Message) | 		decodedMessage, err := decodeMessage(item.Message) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			logx.WithContext(ctx).Errorf("Failed to decode message: %v", err) | 			logx.WithContext(ctx).Errorf("Failed to decode message: %v", err) | ||||||
|  | 
 | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | @ -183,7 +181,7 @@ func (use *CommentUseCase) ListComment(ctx context.Context, req usecase.ListComm | ||||||
| 	return results, total, nil | 	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) | 	replyMap := make(map[string][]*usecase.CommentDocs) | ||||||
| 	// 查詢子留言
 | 	// 查詢子留言
 | ||||||
|  | @ -202,6 +200,7 @@ func (use *CommentUseCase) buildReplies(ctx context.Context, parentComments []*e | ||||||
| 			decodedMessage, err := decodeMessage(sub.Message) | 			decodedMessage, err := decodeMessage(sub.Message) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				logx.WithContext(ctx).Errorf("Failed to decode message: %v", err) | 				logx.WithContext(ctx).Errorf("Failed to decode message: %v", err) | ||||||
|  | 
 | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| 			replyMap[sub.ParentCommentID] = append(replyMap[sub.ParentCommentID], &usecase.CommentDocs{ | 			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) { | func decodeMessage(encodedMessage string) (string, error) { | ||||||
|  |  | ||||||
|  | @ -8,12 +8,13 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"encoding/base64" | 	"encoding/base64" | ||||||
| 	"errors" | 	"errors" | ||||||
|  | 	"testing" | ||||||
|  | 	"time" | ||||||
|  | 
 | ||||||
| 	"github.com/golang/snappy" | 	"github.com/golang/snappy" | ||||||
| 	"github.com/stretchr/testify/assert" | 	"github.com/stretchr/testify/assert" | ||||||
| 	"go.mongodb.org/mongo-driver/bson/primitive" | 	"go.mongodb.org/mongo-driver/bson/primitive" | ||||||
| 	"go.uber.org/mock/gomock" | 	"go.uber.org/mock/gomock" | ||||||
| 	"testing" |  | ||||||
| 	"time" |  | ||||||
| 
 | 
 | ||||||
| 	mockRepo "app-cloudep-comment-server/pkg/mock/repository" | 	mockRepo "app-cloudep-comment-server/pkg/mock/repository" | ||||||
| 	err "app-cloudep-comment-server/pkg/repository" | 	err "app-cloudep-comment-server/pkg/repository" | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue