diff --git a/.golangci.yml b/.golangci.yml index e0419c67c..7ac0de5c3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -174,6 +174,11 @@ linters-settings: # - ^print.*$ - 'fmt\.Print.*' - fmt.Println.* # too much log noise + - ^unsafe\..*$ + - ^init$ + - ^os.Exit$ + - ^fmt.Print.*$ + - ^panic$ - painc # - ginkgo\\.F.* # these are used just for local development # # Exclude godoc examples from forbidigo checks. Default is true. @@ -239,9 +244,6 @@ linters-settings: hugeParam: # size in bytes that makes the warning trigger (default 80) sizeThreshold: 80 - nestingReduce: - # min number of statements inside a branch to trigger a warning (default 5) - bodyWidth: 5 rangeExprCopy: # size in bytes that makes the warning trigger (default 512) sizeThreshold: 512 @@ -255,15 +257,10 @@ linters-settings: ruleguard: # path to a gorules file for the ruleguard checker rules: '' - truncateCmp: - # whether to skip int/uint/uintptr types (default true) - skipArchDependent: true underef: # whether to skip (*x).method() calls where x is a pointer receiver (default true) skipRecvDeref: true - unnamedResult: - # whether to check exported functions - checkExported: true + gocyclo: # minimal code complexity to report, 30 by default (but we recommend 10-20) min-complexity: 30 diff --git a/internal/api/group.go b/internal/api/group.go index 14e6274ef..6cb302819 100644 --- a/internal/api/group.go +++ b/internal/api/group.go @@ -119,7 +119,7 @@ func (o *GroupApi) GetGroupAbstractInfo(c *gin.Context) { // a2r.Call(group.GroupClient.SetGroupMemberNickname, g.userClient, c) //} // -//func (g *Group) GetGroupAllMemberList(c *gin.Context) { +// func (g *Group) GetGroupAllMemberList(c *gin.Context) { // a2r.Call(group.GroupClient.GetGroupAllMember, g.userClient, c) //} diff --git a/internal/push/offlinepush/jpush/body/audience.go b/internal/push/offlinepush/jpush/body/audience.go index 86e9f08d3..9db66ffe6 100644 --- a/internal/push/offlinepush/jpush/body/audience.go +++ b/internal/push/offlinepush/jpush/body/audience.go @@ -33,7 +33,7 @@ func (a *Audience) set(key string, v []string) { a.Object = a.audience } // v, ok = this.audience[key] - //if ok { + // if ok { // return //} a.audience[key] = v diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index 016cea543..82ff859f0 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -315,10 +315,10 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver // Get user IDs with "Do Not Disturb" enabled in super large groups. func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req *pbconversation.GetRecvMsgNotNotifyUserIDsReq) (*pbconversation.GetRecvMsgNotNotifyUserIDsResp, error) { // userIDs, err := c.conversationDatabase.FindRecvMsgNotNotifyUserIDs(ctx, req.GroupID) - //if err != nil { + // if err != nil { // return nil, err //} - //return &pbconversation.GetRecvMsgNotNotifyUserIDsResp{UserIDs: userIDs}, nil + // return &pbconversation.GetRecvMsgNotNotifyUserIDsResp{UserIDs: userIDs}, nil return nil, errors.New("deprecated") } diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 5ef211728..673b3c87b 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -25,8 +25,6 @@ import ( var Config GlobalConfig -const ConfKey = "conf" - type CallBackConfig struct { Enable bool `yaml:"enable"` CallbackTimeOut int `yaml:"timeout"` diff --git a/pkg/common/config/constant.go b/pkg/common/config/constant.go new file mode 100644 index 000000000..46eeaceba --- /dev/null +++ b/pkg/common/config/constant.go @@ -0,0 +1,23 @@ +package config + +const ConfKey = "conf" + +const ( + // DefaultDirPerm is used for creating general directories, allowing the owner to read, write, and execute, + // while the group and others can only read and execute. + DefaultDirPerm = 0755 + + // PrivateFilePerm is used for sensitive files, allowing only the owner to read and write. + PrivateFilePerm = 0600 + + // ExecFilePerm is used for executable files, allowing the owner to read, write, and execute, + // while the group and others can only read. + ExecFilePerm = 0754 + + // SharedDirPerm is used for shared directories, allowing the owner and group to read, write, and execute, + // with no permissions for others. + SharedDirPerm = 0770 + + // ReadOnlyDirPerm is used for read-only directories, allowing the owner, group, and others to only read. + ReadOnlyDirPerm = 0555 +) diff --git a/pkg/common/db/cache/conversation.go b/pkg/common/db/cache/conversation.go index a2fc73e0d..166fc7774 100644 --- a/pkg/common/db/cache/conversation.go +++ b/pkg/common/db/cache/conversation.go @@ -31,9 +31,9 @@ import ( const ( // ConversationKey = "CONVERSATION:" - //conversationIDsKey = "CONVERSATION_IDS:" - //conversationIDsHashKey = "CONVERSATION_IDS_HASH:" - //conversationHasReadSeqKey = "CONVERSATION_HAS_READ_SEQ:" + // conversationIDsKey = "CONVERSATION_IDS:" + // conversationIDsHashKey = "CONVERSATION_IDS_HASH:" + // conversationHasReadSeqKey = "CONVERSATION_HAS_READ_SEQ:" //recvMsgOptKey = "RECV_MSG_OPT:" //superGroupRecvMsgNotNotifyUserIDsKey = "SUPER_GROUP_RECV_MSG_NOT_NOTIFY_USER_IDS:" //superGroupRecvMsgNotNotifyUserIDsHashKey = "SUPER_GROUP_RECV_MSG_NOT_NOTIFY_USER_IDS_HASH:" @@ -108,7 +108,7 @@ type ConversationRedisCache struct { // rdb redis.UniversalClient, // conversationDB *relation.ConversationGorm, // options rockscache.Options, -//) ConversationCache { +// ) ConversationCache { // rcClient := rockscache.NewClient(rdb, options) // // return &ConversationRedisCache{ @@ -237,10 +237,10 @@ func (c *ConversationRedisCache) DelConversations(ownerUserID string, conversati func (c *ConversationRedisCache) GetConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*relationtb.ConversationModel, error) { // var keys []string - //for _, conversarionID := range conversationIDs { + // for _, conversarionID := range conversationIDs { // keys = append(keys, c.getConversationKey(ownerUserID, conversarionID)) //} - //return batchGetCache( + // return batchGetCache( // ctx, // c.rcClient, // keys, @@ -263,10 +263,10 @@ func (c *ConversationRedisCache) GetUserAllConversations(ctx context.Context, ow return nil, err } // var keys []string - //for _, conversarionID := range conversationIDs { + // for _, conversarionID := range conversationIDs { // keys = append(keys, c.getConversationKey(ownerUserID, conversarionID)) //} - //return batchGetCache( + // return batchGetCache( // ctx, // c.rcClient, // keys, diff --git a/pkg/common/db/cache/friend.go b/pkg/common/db/cache/friend.go index 82af07072..bcb6560ad 100644 --- a/pkg/common/db/cache/friend.go +++ b/pkg/common/db/cache/friend.go @@ -30,8 +30,8 @@ import ( const ( friendExpireTime = time.Second * 60 * 60 * 12 // FriendIDsKey = "FRIEND_IDS:" - //TwoWayFriendsIDsKey = "COMMON_FRIENDS_IDS:" - //friendKey = "FRIEND_INFO:". + // TwoWayFriendsIDsKey = "COMMON_FRIENDS_IDS:" + // friendKey = "FRIEND_INFO:". ) // FriendCache is an interface for caching friend-related data. diff --git a/pkg/common/db/cache/group.go b/pkg/common/db/cache/group.go index 20d355c3b..b4e5e5a9a 100644 --- a/pkg/common/db/cache/group.go +++ b/pkg/common/db/cache/group.go @@ -33,9 +33,9 @@ import ( const ( groupExpireTime = time.Second * 60 * 60 * 12 // GroupInfoKey = "GROUP_INFO:" - //groupMemberIDsKey = "GROUP_MEMBER_IDS:" - //groupMembersHashKey = "GROUP_MEMBERS_HASH2:" - //groupMemberInfoKey = "GROUP_MEMBER_INFO:" + // groupMemberIDsKey = "GROUP_MEMBER_IDS:" + // groupMembersHashKey = "GROUP_MEMBERS_HASH2:" + // groupMemberInfoKey = "GROUP_MEMBER_INFO:" //joinedGroupsKey = "JOIN_GROUPS_KEY:" //groupMemberNumKey = "GROUP_MEMBER_NUM_CACHE:" //groupRoleLevelMemberIDsKey = "GROUP_ROLE_LEVEL_MEMBER_IDS:". diff --git a/pkg/common/db/cache/meta_cache.go b/pkg/common/db/cache/meta_cache.go index 26a09a1f0..7173fc59b 100644 --- a/pkg/common/db/cache/meta_cache.go +++ b/pkg/common/db/cache/meta_cache.go @@ -247,7 +247,7 @@ func batchGetCache2[T any, K comparable]( // expire time.Duration, // keyIndexFn func(s string, keys []string) (int, error), // fn func(ctx context.Context) (map[string]T, error), -//) (map[string]T, error) { +// ) (map[string]T, error) { // batchMap, err := rcClient.FetchBatch2(ctx, keys, expire, func(idxs []int) (m map[int]string, err error) { // tArrays, err := fn(ctx) // if err != nil { diff --git a/pkg/common/db/cache/msg.go b/pkg/common/db/cache/msg.go index a124d2185..a5b4817ef 100644 --- a/pkg/common/db/cache/msg.go +++ b/pkg/common/db/cache/msg.go @@ -42,7 +42,7 @@ const ( getuiToken = "GETUI_TOKEN" getuiTaskID = "GETUI_TASK_ID" // SignalCache = "SIGNAL_CACHE:" - //signalListCache = "SIGNAL_LIST_CACHE:". + // signalListCache = "SIGNAL_LIST_CACHE:". FCM_TOKEN = "FCM_TOKEN:" messageCache = "MESSAGE_CACHE:" @@ -508,7 +508,7 @@ func (c *msgCache) UserDeleteMsgs(ctx context.Context, conversationID string, se return nil // pipe := c.rdb.Pipeline() - //for _, seq := range seqs { + // for _, seq := range seqs { // delUserListKey := c.getMessageDelUserListKey(conversationID, seq) // userDelListKey := c.getUserDelList(conversationID, userID) // err := pipe.SAdd(ctx, delUserListKey, userID).Err() @@ -526,8 +526,8 @@ func (c *msgCache) UserDeleteMsgs(ctx context.Context, conversationID string, se // return errs.Wrap(err) // } //} - //_, err := pipe.Exec(ctx) - //return errs.Wrap(err) + // _, err := pipe.Exec(ctx) + // return errs.Wrap(err) } func (c *msgCache) GetUserDelList(ctx context.Context, userID, conversationID string) (seqs []int64, err error) { diff --git a/pkg/common/db/controller/msg_test.go b/pkg/common/db/controller/msg_test.go index 4c2ab20da..1d86dcfba 100644 --- a/pkg/common/db/controller/msg_test.go +++ b/pkg/common/db/controller/msg_test.go @@ -44,7 +44,7 @@ func Test_BatchInsertChat2DB(t *testing.T) { conf.RetainChatRecords = 3650 conf.ChatRecordsClearTime = "0 2 * * 3" - mongo, err := unrelation.NewMongo(conf) + mongo, err := unrelation.NewMongo(&conf.Mongo) if err != nil { t.Fatal(err) } @@ -156,7 +156,7 @@ func GetDB() *commonMsgDatabase { conf.RetainChatRecords = 3650 conf.ChatRecordsClearTime = "0 2 * * 3" - mongo, err := unrelation.NewMongo(conf) + mongo, err := unrelation.NewMongo(&conf.Mongo) if err != nil { panic(err) } diff --git a/pkg/common/db/table/relation/black.go b/pkg/common/db/table/relation/black.go index 3f37b8ac3..073a2f17e 100644 --- a/pkg/common/db/table/relation/black.go +++ b/pkg/common/db/table/relation/black.go @@ -34,7 +34,7 @@ type BlackModelInterface interface { Create(ctx context.Context, blacks []*BlackModel) (err error) Delete(ctx context.Context, blacks []*BlackModel) (err error) // UpdateByMap(ctx context.Context, ownerUserID, blockUserID string, args map[string]any) (err error) - //Update(ctx context.Context, blacks []*BlackModel) (err error) + // Update(ctx context.Context, blacks []*BlackModel) (err error) Find(ctx context.Context, blacks []*BlackModel) (blackList []*BlackModel, err error) Take(ctx context.Context, ownerUserID, blockUserID string) (black *BlackModel, err error) FindOwnerBlacks(ctx context.Context, ownerUserID string, pagination pagination.Pagination) (total int64, blacks []*BlackModel, err error) diff --git a/pkg/common/db/table/relation/group_member.go b/pkg/common/db/table/relation/group_member.go index bf3d5bf63..e77d77e28 100644 --- a/pkg/common/db/table/relation/group_member.go +++ b/pkg/common/db/table/relation/group_member.go @@ -48,7 +48,7 @@ type GroupMemberModelInterface interface { SearchMember(ctx context.Context, keyword string, groupID string, pagination pagination.Pagination) (total int64, groupList []*GroupMemberModel, err error) FindRoleLevelUserIDs(ctx context.Context, groupID string, roleLevel int32) ([]string, error) // MapGroupMemberNum(ctx context.Context, groupIDs []string) (count map[string]uint32, err error) - //FindJoinUserID(ctx context.Context, groupIDs []string) (groupUsers map[string][]string, err error) + // FindJoinUserID(ctx context.Context, groupIDs []string) (groupUsers map[string][]string, err error) FindUserJoinedGroupID(ctx context.Context, userID string) (groupIDs []string, err error) TakeGroupMemberNum(ctx context.Context, groupID string) (count int64, err error) // FindUsersJoinedGroupID(ctx context.Context, userIDs []string) (map[string][]string, error) diff --git a/pkg/common/db/table/unrelation/super_group.go b/pkg/common/db/table/unrelation/super_group.go index e6698139b..ff70a62c9 100644 --- a/pkg/common/db/table/unrelation/super_group.go +++ b/pkg/common/db/table/unrelation/super_group.go @@ -18,17 +18,17 @@ package unrelation // "context" //) // -//const ( +// const ( // CSuperGroup = "super_group" // CUserToSuperGroup = "user_to_super_group" //) // -//type SuperGroupModel struct { +// type SuperGroupModel struct { // GroupID string `bson:"group_id" json:"groupID"` // MemberIDs []string `bson:"member_id_list" json:"memberIDList"` //} // -//func (SuperGroupModel) TableName() string { +// func (SuperGroupModel) TableName() string { // return CSuperGroup //} // diff --git a/pkg/common/db/unrelation/super_group.go b/pkg/common/db/unrelation/super_group.go index 2178f222a..64c44ed54 100644 --- a/pkg/common/db/unrelation/super_group.go +++ b/pkg/common/db/unrelation/super_group.go @@ -27,19 +27,19 @@ package unrelation // "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/unrelation" //) // -//func NewSuperGroupMongoDriver(database *mongo.Database) unrelation.SuperGroupModelInterface { +// func NewSuperGroupMongoDriver(database *mongo.Database) unrelation.SuperGroupModelInterface { // return &SuperGroupMongoDriver{ // superGroupCollection: database.Collection(unrelation.CSuperGroup), // userToSuperGroupCollection: database.Collection(unrelation.CUserToSuperGroup), // } //} // -//type SuperGroupMongoDriver struct { +// type SuperGroupMongoDriver struct { // superGroupCollection *mongo.Collection // userToSuperGroupCollection *mongo.Collection //} // -//func (s *SuperGroupMongoDriver) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDs []string) error { +// func (s *SuperGroupMongoDriver) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDs []string) error { // _, err := s.superGroupCollection.InsertOne(ctx, &unrelation.SuperGroupModel{ // GroupID: groupID, // MemberIDs: initMemberIDs,