mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 02:42:19 +08:00
feat: add openim auto format code
This commit is contained in:
parent
a98bc80b03
commit
c1626947fc
@ -22,7 +22,6 @@ import (
|
|||||||
|
|
||||||
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/tools/errs"
|
|
||||||
"github.com/openimsdk/open-im-server/v3/internal/msgtransfer"
|
"github.com/openimsdk/open-im-server/v3/internal/msgtransfer"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ func (m *MsgTransferCmd) addRunE() {
|
|||||||
m.Command.RunE = func(cmd *cobra.Command, args []string) error {
|
m.Command.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
prometheusPort, err := m.getPrometheusPortFlag(cmd)
|
prometheusPort, err := m.getPrometheusPortFlag(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.Wrap(err, "failed to get Prometheus port")
|
return err
|
||||||
}
|
}
|
||||||
return msgtransfer.StartTransfer(prometheusPort)
|
return msgtransfer.StartTransfer(prometheusPort)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/internal/tools"
|
"github.com/openimsdk/open-im-server/v3/internal/tools"
|
||||||
|
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MsgUtilsCmd struct {
|
type MsgUtilsCmd struct {
|
||||||
@ -137,7 +138,7 @@ func (s *SeqCmd) GetSeqCmd() *cobra.Command {
|
|||||||
s.Command.Run = func(cmdLines *cobra.Command, args []string) {
|
s.Command.Run = func(cmdLines *cobra.Command, args []string) {
|
||||||
_, err := tools.InitMsgTool()
|
_, err := tools.InitMsgTool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
util.ExitWithError(err)
|
||||||
}
|
}
|
||||||
userID := s.getUserIDFlag(cmdLines)
|
userID := s.getUserIDFlag(cmdLines)
|
||||||
superGroupID := s.getSuperGroupIDFlag(cmdLines)
|
superGroupID := s.getSuperGroupIDFlag(cmdLines)
|
||||||
|
|||||||
@ -80,7 +80,7 @@ func (rc *RootCmd) persistentPreRun(cmd *cobra.Command, opts ...func(*CmdOpts))
|
|||||||
cmdOpts := rc.applyOptions(opts...)
|
cmdOpts := rc.applyOptions(opts...)
|
||||||
|
|
||||||
if err := rc.initializeLogger(cmdOpts); err != nil {
|
if err := rc.initializeLogger(cmdOpts); err != nil {
|
||||||
return fmt.Errorf("failed to initialize from config: %w", err)
|
return errs.Wrap(err, "failed to initialize logger")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -164,7 +164,7 @@ func (r *RootCmd) getPrometheusPortFlag(cmd *cobra.Command) (int, error) {
|
|||||||
if err != nil || port == 0 {
|
if err != nil || port == 0 {
|
||||||
port, err = r.PortFromConfig(constant.FlagPrometheusPort)
|
port, err = r.PortFromConfig(constant.FlagPrometheusPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errs.Wrap(err, "error getting prometheus port from config")
|
return 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return port, nil
|
return port, nil
|
||||||
|
|||||||
@ -45,13 +45,13 @@ func (a *RpcCmd) Exec() error {
|
|||||||
a.Command.RunE = func(cmd *cobra.Command, args []string) error {
|
a.Command.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
portFlag, err := a.getPortFlag(cmd)
|
portFlag, err := a.getPortFlag(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.Wrap(err, "error getting port flag")
|
return err
|
||||||
}
|
}
|
||||||
a.port = portFlag
|
a.port = portFlag
|
||||||
|
|
||||||
prometheusPort, err := a.getPrometheusPortFlag(cmd)
|
prometheusPort, err := a.getPrometheusPortFlag(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.Wrap(err, "error getting prometheus port flag")
|
return err
|
||||||
}
|
}
|
||||||
a.prometheusPort = prometheusPort
|
a.prometheusPort = prometheusPort
|
||||||
|
|
||||||
|
|||||||
@ -48,33 +48,32 @@ const (
|
|||||||
updateKeyRevoke
|
updateKeyRevoke
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CommonMsgDatabase defines the interface for message database operations.
|
||||||
type CommonMsgDatabase interface {
|
type CommonMsgDatabase interface {
|
||||||
// 批量插入消息
|
// BatchInsertChat2DB inserts a batch of messages into the database for a specific conversation.
|
||||||
BatchInsertChat2DB(ctx context.Context, conversationID string, msgs []*sdkws.MsgData, currentMaxSeq int64) error
|
BatchInsertChat2DB(ctx context.Context, conversationID string, msgs []*sdkws.MsgData, currentMaxSeq int64) error
|
||||||
// 撤回消息
|
// RevokeMsg revokes a message in a conversation.
|
||||||
RevokeMsg(ctx context.Context, conversationID string, seq int64, revoke *unrelationtb.RevokeModel) error
|
RevokeMsg(ctx context.Context, conversationID string, seq int64, revoke *unrelationtb.RevokeModel) error
|
||||||
// mark as read
|
// MarkSingleChatMsgsAsRead marks messages as read for a single chat by sequence numbers.
|
||||||
MarkSingleChatMsgsAsRead(ctx context.Context, userID string, conversationID string, seqs []int64) error
|
MarkSingleChatMsgsAsRead(ctx context.Context, userID string, conversationID string, seqs []int64) error
|
||||||
// 刪除redis中消息缓存
|
// DeleteMessagesFromCache deletes message caches from Redis by sequence numbers.
|
||||||
DeleteMessagesFromCache(ctx context.Context, conversationID string, seqs []int64) error
|
DeleteMessagesFromCache(ctx context.Context, conversationID string, seqs []int64) error
|
||||||
|
// DelUserDeleteMsgsList deletes user's message deletion list.
|
||||||
DelUserDeleteMsgsList(ctx context.Context, conversationID string, seqs []int64)
|
DelUserDeleteMsgsList(ctx context.Context, conversationID string, seqs []int64)
|
||||||
// incrSeq然后批量插入缓存
|
// BatchInsertChat2Cache increments the sequence number and then batch inserts messages into the cache.
|
||||||
BatchInsertChat2Cache(ctx context.Context, conversationID string, msgs []*sdkws.MsgData) (seq int64, isNewConversation bool, err error)
|
BatchInsertChat2Cache(ctx context.Context, conversationID string, msgs []*sdkws.MsgData) (seq int64, isNewConversation bool, err error)
|
||||||
|
// GetMsgBySeqsRange retrieves messages from MongoDB by a range of sequence numbers.
|
||||||
// 通过seqList获取mongo中写扩散消息
|
|
||||||
GetMsgBySeqsRange(ctx context.Context, userID string, conversationID string, begin, end, num, userMaxSeq int64) (minSeq int64, maxSeq int64, seqMsg []*sdkws.MsgData, err error)
|
GetMsgBySeqsRange(ctx context.Context, userID string, conversationID string, begin, end, num, userMaxSeq int64) (minSeq int64, maxSeq int64, seqMsg []*sdkws.MsgData, err error)
|
||||||
// 通过seqList获取大群在 mongo里面的消息
|
// GetMsgBySeqs retrieves messages for large groups from MongoDB by sequence numbers.
|
||||||
GetMsgBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) (minSeq int64, maxSeq int64, seqMsg []*sdkws.MsgData, err error)
|
GetMsgBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) (minSeq int64, maxSeq int64, seqMsg []*sdkws.MsgData, err error)
|
||||||
// 删除会话消息重置最小seq, remainTime为消息保留的时间单位秒,超时消息删除, 传0删除所有消息(此方法不删除redis cache)
|
// DeleteConversationMsgsAndSetMinSeq deletes conversation messages and resets the minimum sequence number. If `remainTime` is 0, all messages are deleted (this method does not delete Redis cache).
|
||||||
DeleteConversationMsgsAndSetMinSeq(ctx context.Context, conversationID string, remainTime int64) error
|
DeleteConversationMsgsAndSetMinSeq(ctx context.Context, conversationID string, remainTime int64) error
|
||||||
// 用户标记删除过期消息返回标记删除的seq列表
|
// UserMsgsDestruct marks messages for deletion based on destruct time and returns a list of sequence numbers for marked messages.
|
||||||
UserMsgsDestruct(ctx context.Context, userID string, conversationID string, destructTime int64, lastMsgDestructTime time.Time) (seqs []int64, err error)
|
UserMsgsDestruct(ctx context.Context, userID string, conversationID string, destructTime int64, lastMsgDestructTime time.Time) (seqs []int64, err error)
|
||||||
|
// DeleteUserMsgsBySeqs allows a user to delete messages based on sequence numbers.
|
||||||
// 用户根据seq删除消息
|
|
||||||
DeleteUserMsgsBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) error
|
DeleteUserMsgsBySeqs(ctx context.Context, userID string, conversationID string, seqs []int64) error
|
||||||
// 物理删除消息置空
|
// DeleteMsgsPhysicalBySeqs physically deletes messages by emptying them based on sequence numbers.
|
||||||
DeleteMsgsPhysicalBySeqs(ctx context.Context, conversationID string, seqs []int64) error
|
DeleteMsgsPhysicalBySeqs(ctx context.Context, conversationID string, seqs []int64) error
|
||||||
|
|
||||||
SetMaxSeq(ctx context.Context, conversationID string, maxSeq int64) error
|
SetMaxSeq(ctx context.Context, conversationID string, maxSeq int64) error
|
||||||
GetMaxSeqs(ctx context.Context, conversationIDs []string) (map[string]int64, error)
|
GetMaxSeqs(ctx context.Context, conversationIDs []string) (map[string]int64, error)
|
||||||
GetMaxSeq(ctx context.Context, conversationID string) (int64, error)
|
GetMaxSeq(ctx context.Context, conversationID string) (int64, error)
|
||||||
|
|||||||
@ -63,13 +63,7 @@ func NewThirdDatabase(cache cache.MsgModel, logdb relation.LogInterface) ThirdDa
|
|||||||
return &thirdDatabase{cache: cache, logdb: logdb}
|
return &thirdDatabase{cache: cache, logdb: logdb}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *thirdDatabase) FcmUpdateToken(
|
func (t *thirdDatabase) FcmUpdateToken(ctx context.Context, account string, platformID int, fcmToken string, expireTime int64) error {
|
||||||
ctx context.Context,
|
|
||||||
account string,
|
|
||||||
platformID int,
|
|
||||||
fcmToken string,
|
|
||||||
expireTime int64,
|
|
||||||
) error {
|
|
||||||
return t.cache.SetFcmToken(ctx, account, platformID, fcmToken, expireTime)
|
return t.cache.SetFcmToken(ctx, account, platformID, fcmToken, expireTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ func main() {
|
|||||||
latestVersion := defaultTemplateVersion
|
latestVersion := defaultTemplateVersion
|
||||||
|
|
||||||
// getLatestVersion
|
// getLatestVersion
|
||||||
getLatestVersion
|
// getLatestVersion
|
||||||
|
|
||||||
// Construct the download URL
|
// Construct the download URL
|
||||||
downloadURL := fmt.Sprintf("https://github.com/openimsdk/chat/releases/download/%s/chat_Linux_x86_64.tar.gz", latestVersion)
|
downloadURL := fmt.Sprintf("https://github.com/openimsdk/chat/releases/download/%s/chat_Linux_x86_64.tar.gz", latestVersion)
|
||||||
|
|||||||
@ -53,20 +53,35 @@ func (UserModel) TableName() string {
|
|||||||
return UserModelTableName
|
return UserModelTableName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UserModelInterface defines the operations available for managing user models.
|
||||||
type UserModelInterface interface {
|
type UserModelInterface interface {
|
||||||
|
// Create inserts a new user or multiple users into the database.
|
||||||
Create(ctx context.Context, users []*UserModel) (err error)
|
Create(ctx context.Context, users []*UserModel) (err error)
|
||||||
|
|
||||||
|
// UpdateByMap updates a user's information based on a map of changes.
|
||||||
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
|
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
|
||||||
|
|
||||||
|
// Update modifies a user's information in the database.
|
||||||
Update(ctx context.Context, user *UserModel) (err error)
|
Update(ctx context.Context, user *UserModel) (err error)
|
||||||
// 获取指定用户信息 不存在,也不返回错误
|
|
||||||
|
// Find retrieves information for a list of users by their IDs. If a user does not exist, it is simply skipped without returning an error.
|
||||||
Find(ctx context.Context, userIDs []string) (users []*UserModel, err error)
|
Find(ctx context.Context, userIDs []string) (users []*UserModel, err error)
|
||||||
// 获取某个用户信息 不存在,则返回错误
|
|
||||||
|
// Take retrieves a specific user's information by their ID. Returns an error if the user does not exist.
|
||||||
Take(ctx context.Context, userID string) (user *UserModel, err error)
|
Take(ctx context.Context, userID string) (user *UserModel, err error)
|
||||||
// 获取用户信息 不存在,不返回错误
|
|
||||||
|
// Page retrieves a paginated list of users and the total count of users. If no users exist, returns an empty list without an error.
|
||||||
Page(ctx context.Context, pageNumber, showNumber int32) (users []*UserModel, count int64, err error)
|
Page(ctx context.Context, pageNumber, showNumber int32) (users []*UserModel, count int64, err error)
|
||||||
|
|
||||||
|
// GetAllUserID retrieves all user IDs in a paginated manner.
|
||||||
GetAllUserID(ctx context.Context, pageNumber, showNumber int32) (userIDs []string, err error)
|
GetAllUserID(ctx context.Context, pageNumber, showNumber int32) (userIDs []string, err error)
|
||||||
|
|
||||||
|
// GetUserGlobalRecvMsgOpt retrieves a user's global message receiving option.
|
||||||
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)
|
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)
|
||||||
// 获取用户总数
|
|
||||||
|
// CountTotal returns the total number of users before a specified time.
|
||||||
CountTotal(ctx context.Context, before *time.Time) (count int64, err error)
|
CountTotal(ctx context.Context, before *time.Time) (count int64, err error)
|
||||||
// 获取范围内用户增量
|
|
||||||
|
// CountRangeEverydayTotal calculates the daily increment of users within a specified time range.
|
||||||
CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error)
|
CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
"github.com/openimsdk/open-im-server/tools/formitychecker/config"
|
"github.com/openimsdk/open-im-server/tools/formitychecker/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ func CheckDirectory(cfg *config.Config) error {
|
|||||||
for _, targetDir := range cfg.TargetDirs {
|
for _, targetDir := range cfg.TargetDirs {
|
||||||
err := filepath.Walk(targetDir, func(path string, info os.FileInfo, err error) error {
|
err := filepath.Walk(targetDir, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errs.Wrap(err, fmt.Sprintf("error walking directory '%s'", targetDir))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip if the directory is in the ignore list
|
// Skip if the directory is in the ignore list
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user