fix: fix lint erros in pkg/common/config,convert

pull/1263/head
cncsmonster 2 years ago
parent e941e9118c
commit 5d798c73ce

@ -336,6 +336,7 @@ func (c *configStruct) RegisterConf2Registry(registry discoveryregistry.SvcDisco
if err != nil {
return err
}
return registry.RegisterConf2Registry(ConfKey, data)
}
@ -348,5 +349,6 @@ func (c *configStruct) EncodeConfig() []byte {
if err := yaml.NewEncoder(buf).Encode(c); err != nil {
panic(err)
}
return buf.Bytes()
}

@ -21,8 +21,9 @@ import (
"path/filepath"
"github.com/OpenIMSDK/protocol/constant"
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
"gopkg.in/yaml.v3"
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
)
//go:embed version
@ -34,7 +35,7 @@ const (
DefaultFolderPath = "../config/"
)
// getProjectRoot returns the absolute path of the project root directory
// getProjectRoot returns the absolute path of the project root directory.
func GetProjectRoot() string {
b, _ := filepath.Abs(os.Args[0])
@ -56,6 +57,7 @@ func GetOptionsByNotification(cfg NotificationConf) msgprocessor.Options {
opts = msgprocessor.WithOptions(opts, msgprocessor.WithHistory(true), msgprocessor.WithPersistent())
}
opts = msgprocessor.WithOptions(opts, msgprocessor.WithSendMsg(cfg.IsSendMsg))
return opts
}
@ -76,6 +78,7 @@ func initConfig(config interface{}, configName, configFolderPath string) error {
return fmt.Errorf("unmarshal yaml error: %w", err)
}
fmt.Println("use config", configFolderPath)
return nil
}
@ -93,5 +96,5 @@ func InitConfig(configFolderPath string) error {
return err
}
return initConfig(&Config.Notification, NotificationFileName, configFolderPath)
return nil
}

@ -18,7 +18,6 @@ import (
"context"
"github.com/OpenIMSDK/protocol/sdkws"
sdk "github.com/OpenIMSDK/protocol/sdkws"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
)
@ -27,11 +26,11 @@ func BlackDB2Pb(
ctx context.Context,
blackDBs []*relation.BlackModel,
f func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error),
) (blackPbs []*sdk.BlackInfo, err error) {
) (blackPbs []*sdkws.BlackInfo, err error) {
if len(blackDBs) == 0 {
return nil, nil
}
var userIDs []string
userIDs := make([]string, 0, len(blackDBs))
for _, blackDB := range blackDBs {
userIDs = append(userIDs, blackDB.BlockUserID)
}
@ -40,7 +39,7 @@ func BlackDB2Pb(
return nil, err
}
for _, blackDB := range blackDBs {
blackPb := &sdk.BlackInfo{
blackPb := &sdkws.BlackInfo{
OwnerUserID: blackDB.OwnerUserID,
CreateTime: blackDB.CreateTime.Unix(),
AddSource: blackDB.AddSource,
@ -55,5 +54,6 @@ func BlackDB2Pb(
}
blackPbs = append(blackPbs, blackPb)
}
return blackPbs, nil
}

@ -27,6 +27,7 @@ func ConversationDB2Pb(conversationDB *relation.ConversationModel) *conversation
if err := utils.CopyStructFields(conversationPB, conversationDB); err != nil {
return nil
}
return conversationPB
}
@ -39,6 +40,7 @@ func ConversationsDB2Pb(conversationsDB []*relation.ConversationModel) (conversa
conversationPB.LatestMsgDestructTime = conversationDB.LatestMsgDestructTime.Unix()
conversationsPB = append(conversationsPB, conversationPB)
}
return conversationsPB
}
@ -47,6 +49,7 @@ func ConversationPb2DB(conversationPB *conversation.Conversation) *relation.Conv
if err := utils.CopyStructFields(conversationDB, conversationPB); err != nil {
return nil
}
return conversationDB
}
@ -58,5 +61,6 @@ func ConversationsPb2DB(conversationsPB []*conversation.Conversation) (conversat
}
conversationsDB = append(conversationsDB, conversationDB)
}
return conversationsDB
}

@ -16,6 +16,7 @@ package convert
import (
"context"
"fmt"
"github.com/OpenIMSDK/protocol/sdkws"
"github.com/OpenIMSDK/tools/utils"
@ -25,9 +26,13 @@ import (
func FriendPb2DB(friend *sdkws.FriendInfo) *relation.FriendModel {
dbFriend := &relation.FriendModel{}
utils.CopyStructFields(dbFriend, friend)
err := utils.CopyStructFields(dbFriend, friend)
if err != nil {
panic(err)
}
dbFriend.FriendUserID = friend.FriendUser.UserID
dbFriend.CreateTime = utils.UnixSecondToTime(friend.CreateTime)
return dbFriend
}
@ -37,7 +42,10 @@ func FriendDB2Pb(
getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error),
) (*sdkws.FriendInfo, error) {
pbfriend := &sdkws.FriendInfo{FriendUser: &sdkws.UserInfo{}}
utils.CopyStructFields(pbfriend, friendDB)
err := utils.CopyStructFields(pbfriend, friendDB)
if err != nil {
panic(err)
}
users, err := getUsers(ctx, []string{friendDB.FriendUserID})
if err != nil {
return nil, err
@ -47,6 +55,7 @@ func FriendDB2Pb(
pbfriend.FriendUser.FaceURL = users[friendDB.FriendUserID].FaceURL
pbfriend.FriendUser.Ex = users[friendDB.FriendUserID].Ex
pbfriend.CreateTime = friendDB.CreateTime.Unix()
return pbfriend, nil
}
@ -58,7 +67,7 @@ func FriendsDB2Pb(
if len(friendsDB) == 0 {
return nil, nil
}
var userID []string
userID := make([]string, 0, len(friendsDB))
for _, friendDB := range friendsDB {
userID = append(userID, friendDB.FriendUserID)
}
@ -68,7 +77,8 @@ func FriendsDB2Pb(
}
for _, friend := range friendsDB {
friendPb := &sdkws.FriendInfo{FriendUser: &sdkws.UserInfo{}}
utils.CopyStructFields(friendPb, friend)
err2 := utils.CopyStructFields(friendPb, friend)
err = fmt.Errorf("%w, %w", err, err2)
friendPb.FriendUser.UserID = users[friend.FriendUserID].UserID
friendPb.FriendUser.Nickname = users[friend.FriendUserID].Nickname
friendPb.FriendUser.FaceURL = users[friend.FriendUserID].FaceURL
@ -76,7 +86,8 @@ func FriendsDB2Pb(
friendPb.CreateTime = friend.CreateTime.Unix()
friendsPb = append(friendsPb, friendPb)
}
return friendsPb, nil
return friendsPb, err
}
func FriendRequestDB2Pb(
@ -116,5 +127,6 @@ func FriendRequestDB2Pb(
Ex: friendRequest.Ex,
})
}
return res, nil
}

@ -55,6 +55,7 @@ func MsgPb2DB(msg *sdkws.MsgData) *unrelation.MsgDataModel {
msgDataModel.AtUserIDList = msg.AtUserIDList
msgDataModel.AttachedInfo = msg.AttachedInfo
msgDataModel.Ex = msg.Ex
return &msgDataModel
}
@ -95,5 +96,6 @@ func MsgDB2Pb(msgModel *unrelation.MsgDataModel) *sdkws.MsgData {
msg.AtUserIDList = msgModel.AtUserIDList
msg.AttachedInfo = msgModel.AttachedInfo
msg.Ex = msgModel.Ex
return &msg
}

@ -34,6 +34,7 @@ func UsersDB2Pb(users []*relationtb.UserModel) (result []*sdkws.UserInfo) {
userPb.GlobalRecvMsgOpt = user.GlobalRecvMsgOpt
result = append(result, &userPb)
}
return result
}
@ -46,5 +47,6 @@ func UserPb2DB(user *sdkws.UserInfo) *relationtb.UserModel {
userDB.CreateTime = time.UnixMilli(user.CreateTime)
userDB.AppMangerLevel = user.AppMangerLevel
userDB.GlobalRecvMsgOpt = user.GlobalRecvMsgOpt
return &userDB
}

Loading…
Cancel
Save