From 4803c8f004869f570c3e51c61369cb67c409dfda Mon Sep 17 00:00:00 2001 From: longyuqing112 <105913803+longyuqing112@users.noreply.github.com> Date: Mon, 26 Feb 2024 21:47:54 +0800 Subject: [PATCH] /pkg-make lint (#1956) Signed-off-by: longyuqing112 <105913803+longyuqing112@users.noreply.github.com> --- pkg/common/cmd/msg_utils.go | 1 - pkg/common/db/controller/auth.go | 2 +- pkg/common/db/s3/minio/minio.go | 2 +- pkg/common/db/s3/minio/thumbnail.go | 5 ++- pkg/common/db/s3/oss/oss.go | 4 +- pkg/common/db/unrelation/msg.go | 63 +++++++++++++---------------- pkg/rpcclient/notification/group.go | 4 +- pkg/rpcclient/third.go | 6 ++- pkg/statistics/statistics.go | 4 +- 9 files changed, 43 insertions(+), 48 deletions(-) diff --git a/pkg/common/cmd/msg_utils.go b/pkg/common/cmd/msg_utils.go index 8c5ffb16c..dd6d645d7 100644 --- a/pkg/common/cmd/msg_utils.go +++ b/pkg/common/cmd/msg_utils.go @@ -133,7 +133,6 @@ func NewSeqCmd() *SeqCmd { return seqCmd } - func (s *SeqCmd) GetSeqCmd() *cobra.Command { s.Command.Run = func(cmdLines *cobra.Command, args []string) { _, err := tools.InitMsgTool() diff --git a/pkg/common/db/controller/auth.go b/pkg/common/db/controller/auth.go index d3d5f7da9..18c64ad8f 100644 --- a/pkg/common/db/controller/auth.go +++ b/pkg/common/db/controller/auth.go @@ -70,7 +70,7 @@ func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformI } } if len(deleteTokenKey) != 0 { - err := a.cache.DeleteTokenByUidPid(ctx, userID, platformID, deleteTokenKey) + err = a.cache.DeleteTokenByUidPid(ctx, userID, platformID, deleteTokenKey) if err != nil { return "", err } diff --git a/pkg/common/db/s3/minio/minio.go b/pkg/common/db/s3/minio/minio.go index 53a2864ef..81545ff1b 100644 --- a/pkg/common/db/s3/minio/minio.go +++ b/pkg/common/db/s3/minio/minio.go @@ -149,7 +149,7 @@ func (m *Minio) initMinio(ctx context.Context) error { `{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject","s3:PutObject"],"Effect": "Allow","Principal": {"AWS": ["*"]},"Resource": ["arn:aws:s3:::%s/*"],"Sid": ""}]}`, conf.Bucket, ) - if err := m.core.Client.SetBucketPolicy(ctx, conf.Bucket, policy); err != nil { + if err = m.core.Client.SetBucketPolicy(ctx, conf.Bucket, policy); err != nil { return err } } diff --git a/pkg/common/db/s3/minio/thumbnail.go b/pkg/common/db/s3/minio/thumbnail.go index 49c376c9f..5dfdaee09 100644 --- a/pkg/common/db/s3/minio/thumbnail.go +++ b/pkg/common/db/s3/minio/thumbnail.go @@ -82,7 +82,8 @@ func (m *Minio) getImageThumbnailURL(ctx context.Context, name string, expire ti } key, err := m.cache.GetThumbnailKey(ctx, name, opt.Format, opt.Width, opt.Height, func(ctx context.Context) (string, error) { if img == nil { - reader, err := m.core.Client.GetObject(ctx, m.bucket, name, minio.GetObjectOptions{}) + var reader *minio.Object + reader, err = m.core.Client.GetObject(ctx, m.bucket, name, minio.GetObjectOptions{}) if err != nil { return "", err } @@ -103,7 +104,7 @@ func (m *Minio) getImageThumbnailURL(ctx context.Context, name string, expire ti err = gif.Encode(buf, thumbnail, nil) } cacheKey := filepath.Join(imageThumbnailPath, info.Etag, fmt.Sprintf("image_w%d_h%d.%s", opt.Width, opt.Height, opt.Format)) - if _, err := m.core.Client.PutObject(ctx, m.bucket, cacheKey, buf, int64(buf.Len()), minio.PutObjectOptions{}); err != nil { + if _, err = m.core.Client.PutObject(ctx, m.bucket, cacheKey, buf, int64(buf.Len()), minio.PutObjectOptions{}); err != nil { return "", err } return cacheKey, nil diff --git a/pkg/common/db/s3/oss/oss.go b/pkg/common/db/s3/oss/oss.go index 0bba97ee7..98473b87f 100644 --- a/pkg/common/db/s3/oss/oss.go +++ b/pkg/common/db/s3/oss/oss.go @@ -52,10 +52,10 @@ const ( const successCode = http.StatusOK -const ( +/* const ( videoSnapshotImagePng = "png" videoSnapshotImageJpg = "jpg" -) +) */ func NewOSS() (s3.Interface, error) { conf := config.Config.Object.Oss diff --git a/pkg/common/db/unrelation/msg.go b/pkg/common/db/unrelation/msg.go index 1c0686d28..bc9118a9a 100644 --- a/pkg/common/db/unrelation/msg.go +++ b/pkg/common/db/unrelation/msg.go @@ -246,47 +246,42 @@ func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc( indexs = append(indexs, m.model.GetMsgIndex(seq)) } pipeline := mongo.Pipeline{ - { - {"$match", bson.D{ - {"doc_id", docID}, - }}, - }, - { - {"$project", bson.D{ - {"_id", 0}, - {"doc_id", 1}, - {"msgs", bson.D{ - {"$map", bson.D{ - {"input", indexs}, - {"as", "index"}, - {"in", bson.D{ - {"$let", bson.D{ - {"vars", bson.D{ - {"currentMsg", bson.D{ - {"$arrayElemAt", []string{"$msgs", "$$index"}}, - }}, + bson.D{{Key: "$match", Value: bson.D{ + {Key: "doc_id", Value: docID}, + }}}, + bson.D{{Key: "$project", Value: bson.D{ + {Key: "_id", Value: 0}, + {Key: "doc_id", Value: 1}, + {Key: "msgs", Value: bson.D{ + {Key: "$map", Value: bson.D{ + {Key: "input", Value: indexs}, + {Key: "as", Value: "index"}, + {Key: "in", Value: bson.D{ + {Key: "$let", Value: bson.D{ + {Key: "vars", Value: bson.D{ + {Key: "currentMsg", Value: bson.D{ + {Key: "$arrayElemAt", Value: bson.A{"$msgs", "$$index"}}, }}, - {"in", bson.D{ - {"$cond", bson.D{ - {"if", bson.D{ - {"$in", []string{userID, "$$currentMsg.del_list"}}, - }}, - {"then", nil}, - {"else", "$$currentMsg"}, + }}, + {Key: "in", Value: bson.D{ + {Key: "$cond", Value: bson.D{ + {Key: "if", Value: bson.D{ + {Key: "$in", Value: bson.A{userID, "$$currentMsg.del_list"}}, }}, + {Key: "then", Value: nil}, + {Key: "else", Value: "$$currentMsg"}, }}, }}, }}, }}, }}, }}, - }, - { - {"$project", bson.D{ - {"msgs.del_list", 0}, - }}, - }, + }}}, + bson.D{{Key: "$project", Value: bson.D{ + {Key: "msgs.del_list", Value: 0}, + }}}, } + cur, err := m.MsgCollection.Aggregate(ctx, pipeline) if err != nil { return nil, errs.Wrap(err) @@ -800,7 +795,7 @@ func (m *MsgMongoDriver) RangeUserSendCount( } defer cur.Close(ctx) var result []Result - if err := cur.All(ctx, &result); err != nil { + if err = cur.All(ctx, &result); err != nil { return 0, 0, nil, nil, errs.Wrap(err) } if len(result) == 0 { @@ -1049,7 +1044,7 @@ func (m *MsgMongoDriver) RangeGroupSendCount( } defer cur.Close(ctx) var result []Result - if err := cur.All(ctx, &result); err != nil { + if err = cur.All(ctx, &result); err != nil { return 0, 0, nil, nil, errs.Wrap(err) } if len(result) == 0 { diff --git a/pkg/rpcclient/notification/group.go b/pkg/rpcclient/notification/group.go index 8c3719b2c..7f40326b7 100755 --- a/pkg/rpcclient/notification/group.go +++ b/pkg/rpcclient/notification/group.go @@ -410,7 +410,7 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte return err } tips := &sdkws.GroupApplicationAcceptedTips{Group: group, HandleMsg: req.HandledMsg} - if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { + if err = g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } for _, userID := range append(userIDs, req.FromUserID) { @@ -443,7 +443,7 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte return err } tips := &sdkws.GroupApplicationRejectedTips{Group: group, HandleMsg: req.HandledMsg} - if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { + if err = g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } for _, userID := range append(userIDs, req.FromUserID) { diff --git a/pkg/rpcclient/third.go b/pkg/rpcclient/third.go index 73d874005..b3557bf83 100755 --- a/pkg/rpcclient/third.go +++ b/pkg/rpcclient/third.go @@ -42,13 +42,15 @@ func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third { } client := third.NewThirdClient(conn) minioClient, err := minioInit() + if err != nil { + panic(err) + } return &Third{discov: discov, Client: client, conn: conn, MinioClient: minioClient} } func minioInit() (*minio.Client, error) { minioClient := &minio.Client{} - var initUrl string - initUrl = config.Config.Object.Minio.Endpoint + initUrl := config.Config.Object.Minio.Endpoint minioUrl, err := url.Parse(initUrl) if err != nil { return nil, err diff --git a/pkg/statistics/statistics.go b/pkg/statistics/statistics.go index de6d04fec..6dfc8155c 100644 --- a/pkg/statistics/statistics.go +++ b/pkg/statistics/statistics.go @@ -36,9 +36,7 @@ func (s *Statistics) output() { var timeIntervalNum uint64 for { sum = *s.AllCount - select { - case <-t.C: - } + <-t.C if *s.AllCount-sum <= 0 { intervalCount = 0 } else {