diff --git a/.golangci.yaml b/.golangci.yaml index 5518484..c9726ca 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -117,6 +117,14 @@ issues: - gocognit - contextcheck + exclude-dirs: + - internal/model + + exclude-files: + - .*_test.go + + + linters-settings: gci: sections: diff --git a/Makefile b/Makefile index 035a97b..186d9a1 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ test: # 進行測試 fmt: # 格式優化 $(GOFMT) -w $(GOFILES) goimports -w ./ + golangci-lint run .PHONY: gen-rpc gen-rpc: # 建立 rpc code diff --git a/internal/domain/errors.go b/internal/domain/errors.go index 618d6cc..2f18b18 100644 --- a/internal/domain/errors.go +++ b/internal/domain/errors.go @@ -1,7 +1,6 @@ package domain import ( - "fmt" "strings" ers "code.30cm.net/digimon/library-go/errs" @@ -51,9 +50,7 @@ const ( ) func CommentError(ec ErrorCode, s ...string) *ers.LibError { - return ers.NewError(code.CloudEPTweeting, code.DBError, - ec.ToUint32(), - fmt.Sprintf("%s", strings.Join(s, " "))) + return ers.NewError(code.CloudEPTweeting, code.DBError, ec.ToUint32(), strings.Join(s, " ")) } func CommentErrorL(ec ErrorCode, diff --git a/internal/lib/neo4j/neo4j.go b/internal/lib/neo4j/neo4j.go index d8178e7..c110b8a 100644 --- a/internal/lib/neo4j/neo4j.go +++ b/internal/lib/neo4j/neo4j.go @@ -37,7 +37,7 @@ func NewNeo4J(conf *Config, opts ...Option) *Client { // Conn initiates connection to the database and returns a Neo4j driver instance. func (c *Client) Conn() (neo4j.DriverWithContext, error) { auth := neo4j.BasicAuth(c.serviceConf.Username, c.serviceConf.Password, "") - driver, err := neo4j.NewDriverWithContext(c.serviceConf.URI, auth, func(c *n4Cfg.Config) {}) + driver, err := neo4j.NewDriverWithContext(c.serviceConf.URI, auth, func(_ *n4Cfg.Config) {}) if err != nil { return nil, fmt.Errorf("neo4j driver initialization error: %w", err) } diff --git a/internal/logic/commentservice/delete_comment_logic.go b/internal/logic/commentservice/delete_comment_logic.go index 467d027..80ec847 100644 --- a/internal/logic/commentservice/delete_comment_logic.go +++ b/internal/logic/commentservice/delete_comment_logic.go @@ -37,6 +37,7 @@ func (l *DeleteCommentLogic) DeleteComment(in *tweeting.DeleteCommentReq) (*twee {Key: "err", Value: err}, }, "failed to del comment").Wrap(err) + return nil, e } diff --git a/internal/logic/commentservice/get_comments_logic.go b/internal/logic/commentservice/get_comments_logic.go index d22a2cf..d369e1e 100644 --- a/internal/logic/commentservice/get_comments_logic.go +++ b/internal/logic/commentservice/get_comments_logic.go @@ -41,8 +41,8 @@ func convertToCommentDetailItem(item *model.Comment) *tweeting.CommentDetail { Uid: item.UID, Content: item.Content, CreatedAt: item.CreateAt, - LikeCount: int64(item.LikeCount), - DislikeCount: int64(item.DisLikeCount), + LikeCount: item.LikeCount, + DislikeCount: item.DisLikeCount, } } @@ -82,6 +82,7 @@ func (l *GetCommentsLogic) GetComments(in *tweeting.GetCommentsReq) (*tweeting.G {Key: "err", Value: err}, }, "failed to find comment").Wrap(err) + return nil, e } diff --git a/internal/logic/commentservice/update_comment_logic.go b/internal/logic/commentservice/update_comment_logic.go index bc24ef0..5002f72 100644 --- a/internal/logic/commentservice/update_comment_logic.go +++ b/internal/logic/commentservice/update_comment_logic.go @@ -27,16 +27,16 @@ func NewUpdateCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upd } } -type checkCommentId struct { - CommentId string `validate:"required"` +type checkCommentID struct { + CommentID string `validate:"required"` Content string `json:"content,omitempty" validate:"lte=500"` } // UpdateComment 更新評論 func (l *UpdateCommentLogic) UpdateComment(in *tweeting.UpdateCommentReq) (*tweeting.OKResp, error) { // 驗證資料 - if err := l.svcCtx.Validate.ValidateAll(&checkCommentId{ - CommentId: in.GetCommentId(), + if err := l.svcCtx.Validate.ValidateAll(&checkCommentID{ + CommentID: in.GetCommentId(), Content: in.GetContent(), }); err != nil { // 錯誤代碼 05-011-00 @@ -75,6 +75,7 @@ func (l *UpdateCommentLogic) UpdateComment(in *tweeting.UpdateCommentReq) (*twee {Key: "err", Value: err}, }, "failed to update comment:", in.CommentId).Wrap(err) + return nil, e } diff --git a/internal/logic/postservice/create_post_logic.go b/internal/logic/postservice/create_post_logic.go index e3fbb0d..ec00a3c 100644 --- a/internal/logic/postservice/create_post_logic.go +++ b/internal/logic/postservice/create_post_logic.go @@ -32,7 +32,7 @@ type newTweetingReq struct { UID string `json:"uid" validate:"required"` Content string `json:"content" validate:"required,lte=500"` // 貼文限制 500 字內 Tags []string `json:"tags"` - MediaUrl []string `json:"media_url"` + MediaURL []string `json:"media_url"` IsAd bool `json:"is_ad"` // default false } @@ -85,6 +85,7 @@ func (l *CreatePostLogic) CreatePost(in *tweeting.NewPostReq) (*tweeting.PostRes {Key: "err", Value: err}, }, "failed to add new post").Wrap(err) + return nil, e } diff --git a/internal/logic/postservice/delete_post_logic.go b/internal/logic/postservice/delete_post_logic.go index ffa6bda..60256f6 100644 --- a/internal/logic/postservice/delete_post_logic.go +++ b/internal/logic/postservice/delete_post_logic.go @@ -37,6 +37,7 @@ func (l *DeletePostLogic) DeletePost(in *tweeting.DeletePostsReq) (*tweeting.OKR {Key: "err", Value: err}, }, "failed to del post").Wrap(err) + return nil, e } diff --git a/internal/logic/postservice/list_posts_logic.go b/internal/logic/postservice/list_posts_logic.go index 544327d..568d801 100644 --- a/internal/logic/postservice/list_posts_logic.go +++ b/internal/logic/postservice/list_posts_logic.go @@ -54,8 +54,8 @@ func convertToPostDetailItem(item *model.Post) *tweeting.PostDetailItem { IsAd: item.IsAd, CreatedAt: item.CreateAt, UpdateAt: item.UpdateAt, - LikeCount: int64(item.Like), - DislikeCount: int64(item.DisLike), + LikeCount: item.Like, + DislikeCount: item.DisLike, } } @@ -102,6 +102,7 @@ func (l *ListPostsLogic) ListPosts(in *tweeting.QueryPostsReq) (*tweeting.ListPo {Key: "err", Value: err}, }, "failed to find posts").Wrap(err) + return nil, e } diff --git a/internal/logic/postservice/update_post_logic.go b/internal/logic/postservice/update_post_logic.go index 2275fcc..f028b6c 100644 --- a/internal/logic/postservice/update_post_logic.go +++ b/internal/logic/postservice/update_post_logic.go @@ -28,7 +28,7 @@ func NewUpdatePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update } } -type checkPostId struct { +type checkPostID struct { PostID string `validate:"required"` Content string `json:"content,omitempty" validate:"lte=500"` } @@ -36,7 +36,7 @@ type checkPostId struct { // UpdatePost 更新貼文 func (l *UpdatePostLogic) UpdatePost(in *tweeting.UpdatePostReq) (*tweeting.OKResp, error) { // 驗證資料 - if err := l.svcCtx.Validate.ValidateAll(&checkPostId{ + if err := l.svcCtx.Validate.ValidateAll(&checkPostID{ PostID: in.GetPostId(), Content: in.GetContent(), }); err != nil { @@ -53,7 +53,7 @@ func (l *UpdatePostLogic) UpdatePost(in *tweeting.UpdatePostReq) (*tweeting.OKRe update.ID = oid update.Tags = in.GetTags() // 將 Media 存入 - var media []model.Media + media := make([]model.Media, 0, len(in.GetMedia())) for _, item := range in.GetMedia() { media = append(media, model.Media{ Links: item.Url, @@ -88,6 +88,7 @@ func (l *UpdatePostLogic) UpdatePost(in *tweeting.UpdatePostReq) (*tweeting.OKRe {Key: "err", Value: err}, }, "failed to update post", in.PostId).Wrap(err) + return nil, e } diff --git a/internal/logic/socialnetworkservice/get_followee_count_logic.go b/internal/logic/socialnetworkservice/get_followee_count_logic.go index 3cd8227..d5b4385 100644 --- a/internal/logic/socialnetworkservice/get_followee_count_logic.go +++ b/internal/logic/socialnetworkservice/get_followee_count_logic.go @@ -2,9 +2,10 @@ package socialnetworkservicelogic import ( "app-cloudep-tweeting-service/internal/domain" - ers "code.30cm.net/digimon/library-go/errs" "context" + ers "code.30cm.net/digimon/library-go/errs" + "app-cloudep-tweeting-service/gen_result/pb/tweeting" "app-cloudep-tweeting-service/internal/svc" diff --git a/internal/logic/socialnetworkservice/get_followee_logic.go b/internal/logic/socialnetworkservice/get_followee_logic.go index 4a6ad59..73d28d1 100644 --- a/internal/logic/socialnetworkservice/get_followee_logic.go +++ b/internal/logic/socialnetworkservice/get_followee_logic.go @@ -3,9 +3,10 @@ package socialnetworkservicelogic import ( "app-cloudep-tweeting-service/internal/domain" "app-cloudep-tweeting-service/internal/domain/repository" - ers "code.30cm.net/digimon/library-go/errs" "context" + ers "code.30cm.net/digimon/library-go/errs" + "app-cloudep-tweeting-service/gen_result/pb/tweeting" "app-cloudep-tweeting-service/internal/svc" diff --git a/internal/logic/socialnetworkservice/get_follower_count_logic.go b/internal/logic/socialnetworkservice/get_follower_count_logic.go index 7d9b748..2cd9bb7 100644 --- a/internal/logic/socialnetworkservice/get_follower_count_logic.go +++ b/internal/logic/socialnetworkservice/get_follower_count_logic.go @@ -2,9 +2,10 @@ package socialnetworkservicelogic import ( "app-cloudep-tweeting-service/internal/domain" - ers "code.30cm.net/digimon/library-go/errs" "context" + ers "code.30cm.net/digimon/library-go/errs" + "app-cloudep-tweeting-service/gen_result/pb/tweeting" "app-cloudep-tweeting-service/internal/svc" diff --git a/internal/logic/socialnetworkservice/get_follower_logic.go b/internal/logic/socialnetworkservice/get_follower_logic.go index 7dd72f7..f6c4234 100644 --- a/internal/logic/socialnetworkservice/get_follower_logic.go +++ b/internal/logic/socialnetworkservice/get_follower_logic.go @@ -3,9 +3,10 @@ package socialnetworkservicelogic import ( "app-cloudep-tweeting-service/internal/domain" "app-cloudep-tweeting-service/internal/domain/repository" - ers "code.30cm.net/digimon/library-go/errs" "context" + ers "code.30cm.net/digimon/library-go/errs" + "app-cloudep-tweeting-service/gen_result/pb/tweeting" "app-cloudep-tweeting-service/internal/svc" diff --git a/internal/logic/socialnetworkservice/mark_follow_relation_logic.go b/internal/logic/socialnetworkservice/mark_follow_relation_logic.go index ce133de..0e1465c 100644 --- a/internal/logic/socialnetworkservice/mark_follow_relation_logic.go +++ b/internal/logic/socialnetworkservice/mark_follow_relation_logic.go @@ -2,9 +2,10 @@ package socialnetworkservicelogic import ( "app-cloudep-tweeting-service/internal/domain" - ers "code.30cm.net/digimon/library-go/errs" "context" + ers "code.30cm.net/digimon/library-go/errs" + "app-cloudep-tweeting-service/gen_result/pb/tweeting" "app-cloudep-tweeting-service/internal/svc" diff --git a/internal/logic/socialnetworkservice/remove_follow_relation_logic.go b/internal/logic/socialnetworkservice/remove_follow_relation_logic.go index fa40e79..eff0d15 100644 --- a/internal/logic/socialnetworkservice/remove_follow_relation_logic.go +++ b/internal/logic/socialnetworkservice/remove_follow_relation_logic.go @@ -2,9 +2,10 @@ package socialnetworkservicelogic import ( "app-cloudep-tweeting-service/internal/domain" - ers "code.30cm.net/digimon/library-go/errs" "context" + ers "code.30cm.net/digimon/library-go/errs" + "app-cloudep-tweeting-service/gen_result/pb/tweeting" "app-cloudep-tweeting-service/internal/svc" diff --git a/internal/logic/timelineservice/add_post_logic.go b/internal/logic/timelineservice/add_post_logic.go index 6a51a13..53910e4 100644 --- a/internal/logic/timelineservice/add_post_logic.go +++ b/internal/logic/timelineservice/add_post_logic.go @@ -69,6 +69,7 @@ func (l *AddPostLogic) AddPost(in *tweeting.AddPostToTimelineReq) (*tweeting.OKR {Key: "err", Value: err}, }, "failed to insert timeline repo :", in.GetUid()).Wrap(err) + return nil, e } diff --git a/internal/logic/timelineservice/clear_no_more_data_flag_logic.go b/internal/logic/timelineservice/clear_no_more_data_flag_logic.go index 050a7e7..ca8e961 100644 --- a/internal/logic/timelineservice/clear_no_more_data_flag_logic.go +++ b/internal/logic/timelineservice/clear_no_more_data_flag_logic.go @@ -52,6 +52,7 @@ func (l *ClearNoMoreDataFlagLogic) ClearNoMoreDataFlag(in *tweeting.DoNoMoreData {Key: "err", Value: err}, }, "failed to clear no more data flag timeline repo :", in.GetUid()).Wrap(err) + return nil, e } diff --git a/internal/logic/timelineservice/fetch_timeline_logic.go b/internal/logic/timelineservice/fetch_timeline_logic.go index 46ada2e..74f89d4 100644 --- a/internal/logic/timelineservice/fetch_timeline_logic.go +++ b/internal/logic/timelineservice/fetch_timeline_logic.go @@ -61,6 +61,7 @@ func (l *FetchTimelineLogic) FetchTimeline(in *tweeting.GetTimelineReq) (*tweeti {Key: "err", Value: err}, }, "failed to fetch timeline repo :", in.GetUid()).Wrap(err) + return nil, e } diff --git a/internal/logic/timelineservice/has_no_more_data_logic.go b/internal/logic/timelineservice/has_no_more_data_logic.go index 56d7f90..6146ffe 100644 --- a/internal/logic/timelineservice/has_no_more_data_logic.go +++ b/internal/logic/timelineservice/has_no_more_data_logic.go @@ -52,6 +52,7 @@ func (l *HasNoMoreDataLogic) HasNoMoreData(in *tweeting.DoNoMoreDataReq) (*tweet {Key: "err", Value: err}, }, "failed to get no more data flag:", in.GetUid()).Wrap(err) + return nil, e } diff --git a/internal/logic/timelineservice/set_no_more_data_flag_logic.go b/internal/logic/timelineservice/set_no_more_data_flag_logic.go index 321a0d0..59da4df 100644 --- a/internal/logic/timelineservice/set_no_more_data_flag_logic.go +++ b/internal/logic/timelineservice/set_no_more_data_flag_logic.go @@ -52,6 +52,7 @@ func (l *SetNoMoreDataFlagLogic) SetNoMoreDataFlag(in *tweeting.DoNoMoreDataReq) {Key: "err", Value: err}, }, "failed to set no more data flag:", in.GetUid()).Wrap(err) + return nil, e } diff --git a/internal/repository/social_network.go b/internal/repository/social_network.go index 73ef3c4..978f670 100644 --- a/internal/repository/social_network.go +++ b/internal/repository/social_network.go @@ -6,6 +6,9 @@ import ( client4J "app-cloudep-tweeting-service/internal/lib/neo4j" "context" "fmt" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/neo4j/neo4j-go-driver/v5/neo4j" ) @@ -27,6 +30,7 @@ func MustSocialNetworkRepository(param SocialNetworkParam) repository.SocialNetw } func (s *SocialNetworkRepository) CreateUserNode(ctx context.Context, uid string) error { + //nolint:contextcheck session, err := s.neo4jClient.Conn() if err != nil { return err @@ -53,6 +57,7 @@ func (s *SocialNetworkRepository) CreateUserNode(ctx context.Context, uid string } func (s *SocialNetworkRepository) MarkFollowerRelation(ctx context.Context, fromUID, toUID string) error { + //nolint:contextcheck session, err := s.neo4jClient.Conn() if err != nil { return err @@ -88,6 +93,7 @@ func (s *SocialNetworkRepository) MarkFollowerRelation(ctx context.Context, from } func (s *SocialNetworkRepository) GetFollower(ctx context.Context, req repository.FollowReq) (repository.FollowResp, error) { + //nolint:contextcheck session, err := s.neo4jClient.Conn() if err != nil { return repository.FollowResp{}, err @@ -113,11 +119,17 @@ func (s *SocialNetworkRepository) GetFollower(ctx context.Context, req repositor return repository.FollowResp{}, err } - var uids []string + var uidList []string for run.Next(ctx) { record := run.Record() - if uid, ok := record.Get("uid"); ok { - uids = append(uids, uid.(string)) + uid, ok := record.Get("uid") + if ok { + if uidStr, ok := uid.(string); ok { + uidList = append(uidList, uidStr) + } else { + // TODO 可以印 log + continue + } } } @@ -127,12 +139,13 @@ func (s *SocialNetworkRepository) GetFollower(ctx context.Context, req repositor } return repository.FollowResp{ - UIDs: uids, + UIDs: uidList, Total: total, }, nil } func (s *SocialNetworkRepository) GetFollowee(ctx context.Context, req repository.FollowReq) (repository.FollowResp, error) { + //nolint:contextcheck session, err := s.neo4jClient.Conn() if err != nil { return repository.FollowResp{}, err @@ -158,11 +171,17 @@ func (s *SocialNetworkRepository) GetFollowee(ctx context.Context, req repositor return repository.FollowResp{}, err } - var uids []string + var uidList []string for run.Next(ctx) { record := run.Record() - if uid, ok := record.Get("uid"); ok { - uids = append(uids, uid.(string)) + uid, ok := record.Get("uid") + if ok { + if uidStr, ok := uid.(string); ok { + uidList = append(uidList, uidStr) + } else { + // 可以印 log + continue + } } } @@ -172,12 +191,13 @@ func (s *SocialNetworkRepository) GetFollowee(ctx context.Context, req repositor } return repository.FollowResp{ - UIDs: uids, + UIDs: uidList, Total: total, }, nil } func (s *SocialNetworkRepository) GetFollowerCount(ctx context.Context, uid string) (int64, error) { + //nolint:contextcheck session, err := s.neo4jClient.Conn() if err != nil { return 0, err @@ -204,7 +224,11 @@ func (s *SocialNetworkRepository) GetFollowerCount(ctx context.Context, uid stri if run.Next(ctx) { record := run.Record() if followerCount, ok := record.Get("followerCount"); ok { - count = followerCount.(int64) + if dc, ok := followerCount.(int64); ok { + count = dc + } else { + logx.Info("followerCount error") + } } } @@ -212,6 +236,7 @@ func (s *SocialNetworkRepository) GetFollowerCount(ctx context.Context, uid stri } func (s *SocialNetworkRepository) GetFolloweeCount(ctx context.Context, uid string) (int64, error) { + //nolint:contextcheck session, err := s.neo4jClient.Conn() if err != nil { return 0, err @@ -238,7 +263,11 @@ func (s *SocialNetworkRepository) GetFolloweeCount(ctx context.Context, uid stri if run.Next(ctx) { record := run.Record() if followeeCount, ok := record.Get("followeeCount"); ok { - count = followeeCount.(int64) + if dc, ok := followeeCount.(int64); ok { + count = dc + } else { + logx.Info("followeeCount error") + } } } @@ -246,6 +275,7 @@ func (s *SocialNetworkRepository) GetFolloweeCount(ctx context.Context, uid stri } func (s *SocialNetworkRepository) RemoveFollowerRelation(ctx context.Context, fromUID, toUID string) error { + //nolint:contextcheck session, err := s.neo4jClient.Conn() if err != nil { return err @@ -274,6 +304,7 @@ func (s *SocialNetworkRepository) RemoveFollowerRelation(ctx context.Context, fr // GetDegreeBetweenUsers 取得這兩個點之間的度數 (最短路徑長度) func (s *SocialNetworkRepository) GetDegreeBetweenUsers(ctx context.Context, uid1, uid2 string) (int64, error) { + //nolint:contextcheck session, err := s.neo4jClient.Conn() if err != nil { return 0, err @@ -302,7 +333,11 @@ func (s *SocialNetworkRepository) GetDegreeBetweenUsers(ctx context.Context, uid if run.Next(ctx) { record := run.Record() if deg, ok := record.Get("degree"); ok { - degree = deg.(int64) + if degreeValue, ok := deg.(int64); ok { + degree = degreeValue + } else { + logx.Info("degree error") + } } } @@ -311,6 +346,7 @@ func (s *SocialNetworkRepository) GetDegreeBetweenUsers(ctx context.Context, uid // GetUIDsWithinNDegrees 取得某個節點在 n 度內關係所有 UID func (s *SocialNetworkRepository) GetUIDsWithinNDegrees(ctx context.Context, uid string, degrees, pageSize, pageIndex int64) ([]string, int64, error) { + //nolint:contextcheck session, err := s.neo4jClient.Conn() if err != nil { return nil, 0, err @@ -339,11 +375,17 @@ func (s *SocialNetworkRepository) GetUIDsWithinNDegrees(ctx context.Context, uid return nil, 0, fmt.Errorf("failed to get uids within %d degrees of user: %w", degrees, err) } - var uids []string + var uidList []string for run.Next(ctx) { record := run.Record() - if uid, ok := record.Get("uid"); ok { - uids = append(uids, uid.(string)) + uid, ok := record.Get("uid") + if ok { + if uidStr, ok := uid.(string); ok { + uidList = append(uidList, uidStr) + } else { + // 可以印 log + continue + } } } @@ -353,10 +395,11 @@ func (s *SocialNetworkRepository) GetUIDsWithinNDegrees(ctx context.Context, uid return nil, 0, err } - return uids, totalCount, nil + return uidList, totalCount, nil } func (s *SocialNetworkRepository) getTotalUIDsWithinNDegrees(ctx context.Context, uid string, degrees int64) (int64, error) { + //nolint:contextcheck session, err := s.neo4jClient.Conn() if err != nil { return 0, err @@ -384,7 +427,11 @@ func (s *SocialNetworkRepository) getTotalUIDsWithinNDegrees(ctx context.Context if run.Next(ctx) { record := run.Record() if count, ok := record.Get("totalCount"); ok { - totalCount = count.(int64) + if countV, ok := count.(int64); ok { + totalCount = countV + } else { + logx.Info("totalCount error") + } } } diff --git a/internal/repository/timeline_sort_by_timestamp.go b/internal/repository/timeline_sort_by_timestamp.go index 9599c71..ebf4c1d 100644 --- a/internal/repository/timeline_sort_by_timestamp.go +++ b/internal/repository/timeline_sort_by_timestamp.go @@ -139,5 +139,6 @@ func (t *TimelineRepository) ClearNoMoreDataFlag(ctx context.Context, uid string key := domain.TimelineRedisKey.With(uid).ToString() // 移除 "NoMoreData" 標誌 _, err := t.redis.ZremCtx(ctx, key, domain.LastOfTimelineFlag) + return err } diff --git a/internal/server/commentservice/comment_service_server.go b/internal/server/commentservice/comment_service_server.go index f434bad..9fed63f 100644 --- a/internal/server/commentservice/comment_service_server.go +++ b/internal/server/commentservice/comment_service_server.go @@ -7,7 +7,7 @@ import ( "context" "app-cloudep-tweeting-service/gen_result/pb/tweeting" - "app-cloudep-tweeting-service/internal/logic/commentservice" + commentservicelogic "app-cloudep-tweeting-service/internal/logic/commentservice" "app-cloudep-tweeting-service/internal/svc" ) diff --git a/internal/server/postservice/post_service_server.go b/internal/server/postservice/post_service_server.go index 07d52d3..639c1f4 100644 --- a/internal/server/postservice/post_service_server.go +++ b/internal/server/postservice/post_service_server.go @@ -7,7 +7,7 @@ import ( "context" "app-cloudep-tweeting-service/gen_result/pb/tweeting" - "app-cloudep-tweeting-service/internal/logic/postservice" + postservicelogic "app-cloudep-tweeting-service/internal/logic/postservice" "app-cloudep-tweeting-service/internal/svc" ) diff --git a/internal/server/socialnetworkservice/social_network_service_server.go b/internal/server/socialnetworkservice/social_network_service_server.go index a0d8859..efb9003 100644 --- a/internal/server/socialnetworkservice/social_network_service_server.go +++ b/internal/server/socialnetworkservice/social_network_service_server.go @@ -7,7 +7,7 @@ import ( "context" "app-cloudep-tweeting-service/gen_result/pb/tweeting" - "app-cloudep-tweeting-service/internal/logic/socialnetworkservice" + socialnetworkservicelogic "app-cloudep-tweeting-service/internal/logic/socialnetworkservice" "app-cloudep-tweeting-service/internal/svc" ) diff --git a/internal/server/timelineservice/timeline_service_server.go b/internal/server/timelineservice/timeline_service_server.go index 771d6c7..2d2dc03 100644 --- a/internal/server/timelineservice/timeline_service_server.go +++ b/internal/server/timelineservice/timeline_service_server.go @@ -7,7 +7,7 @@ import ( "context" "app-cloudep-tweeting-service/gen_result/pb/tweeting" - "app-cloudep-tweeting-service/internal/logic/timelineservice" + timelineservicelogic "app-cloudep-tweeting-service/internal/logic/timelineservice" "app-cloudep-tweeting-service/internal/svc" ) diff --git a/internal/svc/init_mongo.go b/internal/svc/init_mongo.go index d815d98..8f9bf1e 100644 --- a/internal/svc/init_mongo.go +++ b/internal/svc/init_mongo.go @@ -6,7 +6,7 @@ import ( "fmt" ) -func mustMongoConnectUrl(c config.Config) string { +func mustMongoConnectURL(c config.Config) string { return fmt.Sprintf("%s://%s:%s", c.Mongo.Schema, c.Mongo.Host, @@ -18,10 +18,12 @@ func mustMongoConnectUrl(c config.Config) string { func MustPostModel(c config.Config) model.PostModel { postCollection := model.Post{} - return model.NewPostModel(mustMongoConnectUrl(c), c.Mongo.Database, postCollection.CollectionName()) + + return model.NewPostModel(mustMongoConnectURL(c), c.Mongo.Database, postCollection.CollectionName()) } func MustCommentModel(c config.Config) model.CommentModel { m := model.Comment{} - return model.NewCommentModel(mustMongoConnectUrl(c), c.Mongo.Database, m.CollectionName()) + + return model.NewCommentModel(mustMongoConnectURL(c), c.Mongo.Database, m.CollectionName()) } diff --git a/internal/svc/service_context.go b/internal/svc/service_context.go index e70b793..0c63516 100644 --- a/internal/svc/service_context.go +++ b/internal/svc/service_context.go @@ -6,6 +6,7 @@ import ( "app-cloudep-tweeting-service/internal/lib/neo4j" model "app-cloudep-tweeting-service/internal/model/mongo" "app-cloudep-tweeting-service/internal/repository" + "github.com/zeromicro/go-zero/core/stores/redis" vi "code.30cm.net/digimon/library-go/validator" diff --git a/tweeting.go b/tweeting.go index 173ffd1..45b83b2 100644 --- a/tweeting.go +++ b/tweeting.go @@ -1,9 +1,6 @@ package main import ( - "flag" - "fmt" - "app-cloudep-tweeting-service/gen_result/pb/tweeting" "app-cloudep-tweeting-service/internal/config" commentserviceServer "app-cloudep-tweeting-service/internal/server/commentservice" @@ -11,6 +8,8 @@ import ( socialnetworkserviceServer "app-cloudep-tweeting-service/internal/server/socialnetworkservice" timelineserviceServer "app-cloudep-tweeting-service/internal/server/timelineservice" "app-cloudep-tweeting-service/internal/svc" + "flag" + "log" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/core/service" @@ -40,6 +39,6 @@ func main() { }) defer s.Stop() - fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) + log.Printf("Starting rpc server at %s...\n", c.ListenOn) s.Start() }