fix: fix rest lint errors in pkg

pull/1263/head
cncsmonster 2 years ago
parent 4bd9acbd6d
commit 85cab0b4b3

@ -4,12 +4,14 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"time"
"github.com/OpenIMSDK/tools/discoveryregistry" "github.com/OpenIMSDK/tools/discoveryregistry"
openkeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper" openkeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper"
"github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/log"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"google.golang.org/grpc" "google.golang.org/grpc"
"time"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
) )
func NewDiscoveryRegister(envType string) (discoveryregistry.SvcDiscoveryRegistry, error) { func NewDiscoveryRegister(envType string) (discoveryregistry.SvcDiscoveryRegistry, error) {
@ -28,6 +30,7 @@ func NewDiscoveryRegister(envType string) (discoveryregistry.SvcDiscoveryRegistr
client = nil client = nil
err = errors.New("envType not correct") err = errors.New("envType not correct")
} }
return client, err return client, err
} }
@ -42,47 +45,51 @@ func NewK8sDiscoveryRegister() (discoveryregistry.SvcDiscoveryRegistry, error) {
func (cli *K8sDR) Register(serviceName, host string, port int, opts ...grpc.DialOption) error { func (cli *K8sDR) Register(serviceName, host string, port int, opts ...grpc.DialOption) error {
cli.rpcRegisterAddr = serviceName cli.rpcRegisterAddr = serviceName
return nil return nil
} }
func (cli *K8sDR) UnRegister() error {
func (cli *K8sDR) UnRegister() error {
return nil return nil
} }
func (cli *K8sDR) CreateRpcRootNodes(serviceNames []string) error {
func (cli *K8sDR) CreateRpcRootNodes(serviceNames []string) error {
return nil return nil
} }
func (cli *K8sDR) RegisterConf2Registry(key string, conf []byte) error {
func (cli *K8sDR) RegisterConf2Registry(key string, conf []byte) error {
return nil return nil
} }
func (cli *K8sDR) GetConfFromRegistry(key string) ([]byte, error) { func (cli *K8sDR) GetConfFromRegistry(key string) ([]byte, error) {
return nil, nil return nil, nil
} }
func (cli *K8sDR) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error) {
func (cli *K8sDR) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error) {
conn, err := grpc.DialContext(ctx, serviceName, append(cli.options, opts...)...) conn, err := grpc.DialContext(ctx, serviceName, append(cli.options, opts...)...)
return []*grpc.ClientConn{conn}, err return []*grpc.ClientConn{conn}, err
} }
func (cli *K8sDR) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
func (cli *K8sDR) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
return grpc.DialContext(ctx, serviceName, append(cli.options, opts...)...) return grpc.DialContext(ctx, serviceName, append(cli.options, opts...)...)
} }
func (cli *K8sDR) GetSelfConnTarget() string {
func (cli *K8sDR) GetSelfConnTarget() string {
return cli.rpcRegisterAddr return cli.rpcRegisterAddr
} }
func (cli *K8sDR) AddOption(opts ...grpc.DialOption) { func (cli *K8sDR) AddOption(opts ...grpc.DialOption) {
cli.options = append(cli.options, opts...) cli.options = append(cli.options, opts...)
} }
func (cli *K8sDR) CloseConn(conn *grpc.ClientConn) { func (cli *K8sDR) CloseConn(conn *grpc.ClientConn) {
conn.Close() conn.Close()
} }
// do not use this method for call rpc // do not use this method for call rpc.
func (cli *K8sDR) GetClientLocalConns() map[string][]*grpc.ClientConn { func (cli *K8sDR) GetClientLocalConns() map[string][]*grpc.ClientConn {
fmt.Println("should not call this function!!!!!!!!!!!!!!!!!!!!!!!!!") fmt.Println("should not call this function!!!!!!!!!!!!!!!!!!!!!!!!!")
return nil return nil
} }

@ -34,16 +34,21 @@ import (
var client http.Client var client http.Client
func Get(url string) (response []byte, err error) { func Get(url string) (response []byte, err error) {
client := http.Client{Timeout: 5 * time.Second} clientGet := http.Client{Timeout: 5 * time.Second}
resp, err := client.Get(url) req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp, err2 := clientGet.Do(req)
if err2 != nil {
return nil, err
}
defer resp.Body.Close() defer resp.Body.Close()
body, err := io.ReadAll(resp.Body) body, err3 := io.ReadAll(resp.Body)
if err != nil { if err3 != nil {
return nil, err return nil, err
} }
return body, nil return body, nil
} }
@ -83,6 +88,7 @@ func Post(
if err != nil { if err != nil {
return nil, err return nil, err
} }
return result, nil return result, nil
} }
@ -98,6 +104,7 @@ func PostReturn(
return err return err
} }
err = json.Unmarshal(b, output) err = json.Unmarshal(b, output)
return err return err
} }
@ -116,17 +123,22 @@ func callBackPostReturn(
if err != nil { if err != nil {
if callbackConfig.CallbackFailedContinue != nil && *callbackConfig.CallbackFailedContinue { if callbackConfig.CallbackFailedContinue != nil && *callbackConfig.CallbackFailedContinue {
log.ZWarn(ctx, "callback failed but continue", err, "url", url) log.ZWarn(ctx, "callback failed but continue", err, "url", url)
return errs.ErrCallbackContinue return errs.ErrCallbackContinue
} }
return errs.ErrNetwork.Wrap(err.Error()) return errs.ErrNetwork.Wrap(err.Error())
} }
if err = json.Unmarshal(b, output); err != nil { if err = json.Unmarshal(b, output); err != nil {
if callbackConfig.CallbackFailedContinue != nil && *callbackConfig.CallbackFailedContinue { if callbackConfig.CallbackFailedContinue != nil && *callbackConfig.CallbackFailedContinue {
log.ZWarn(ctx, "callback failed but continue", err, "url", url) log.ZWarn(ctx, "callback failed but continue", err, "url", url)
return errs.ErrCallbackContinue return errs.ErrCallbackContinue
} }
return errs.ErrData.Wrap(err.Error()) return errs.ErrData.Wrap(err.Error())
} }
return output.Parse() return output.Parse()
} }

@ -51,6 +51,7 @@ func NewMConsumerGroup(consumerConfig *MConsumerGroupConfig, topics, addrs []str
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())
} }
return &MConsumerGroup{ return &MConsumerGroup{
consumerGroup, consumerGroup,
groupID, groupID,

@ -67,6 +67,7 @@ func NewKafkaProducer(addr []string, topic string) *Producer {
producer, err = sarama.NewSyncProducer(p.addr, p.config) // Initialize the client producer, err = sarama.NewSyncProducer(p.addr, p.config) // Initialize the client
if err == nil { if err == nil {
p.producer = producer p.producer = producer
return &p return &p
} }
//TODO If the password is wrong, exit directly //TODO If the password is wrong, exit directly
@ -83,6 +84,7 @@ func NewKafkaProducer(addr []string, topic string) *Producer {
panic(err.Error()) panic(err.Error())
} }
p.producer = producer p.producer = producer
return &p return &p
} }
@ -91,6 +93,7 @@ func GetMQHeaderWithContext(ctx context.Context) ([]sarama.RecordHeader, error)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return []sarama.RecordHeader{ return []sarama.RecordHeader{
{Key: []byte(constant.OperationID), Value: []byte(operationID)}, {Key: []byte(constant.OperationID), Value: []byte(operationID)},
{Key: []byte(constant.OpUserID), Value: []byte(opUserID)}, {Key: []byte(constant.OpUserID), Value: []byte(opUserID)},
@ -100,10 +103,11 @@ func GetMQHeaderWithContext(ctx context.Context) ([]sarama.RecordHeader, error)
} }
func GetContextWithMQHeader(header []*sarama.RecordHeader) context.Context { func GetContextWithMQHeader(header []*sarama.RecordHeader) context.Context {
var values []string values := make([]string, 0, len(header))
for _, recordHeader := range header { for _, recordHeader := range header {
values = append(values, string(recordHeader.Value)) values = append(values, string(recordHeader.Value))
} }
return mcontext.WithMustInfoCtx(values) // TODO return mcontext.WithMustInfoCtx(values) // TODO
} }
@ -134,5 +138,6 @@ func (p *Producer) SendMessage(ctx context.Context, key string, msg proto.Messag
if err == nil { if err == nil {
prome.Inc(prome.SendMsgCounter) prome.Inc(prome.SendMsgCounter)
} }
return partition, offset, utils.Wrap(err, "") return partition, offset, utils.Wrap(err, "")
} }

@ -42,11 +42,13 @@ func (l *LockerMessage) LockMessageTypeKey(ctx context.Context, clientMsgID, typ
err = l.cache.LockMessageTypeKey(ctx, clientMsgID, typeKey) err = l.cache.LockMessageTypeKey(ctx, clientMsgID, typeKey)
if err != nil { if err != nil {
time.Sleep(time.Millisecond * 100) time.Sleep(time.Millisecond * 100)
continue continue
} else { } else {
break break
} }
} }
return err return err
} }
@ -55,11 +57,13 @@ func (l *LockerMessage) LockGlobalMessage(ctx context.Context, clientMsgID strin
err = l.cache.LockMessageTypeKey(ctx, clientMsgID, GlOBALLOCK) err = l.cache.LockMessageTypeKey(ctx, clientMsgID, GlOBALLOCK)
if err != nil { if err != nil {
time.Sleep(time.Millisecond * 100) time.Sleep(time.Millisecond * 100)
continue continue
} else { } else {
break break
} }
} }
return err return err
} }

@ -79,6 +79,7 @@ var (
ConversationCreateFailedCounter prometheus.Counter ConversationCreateFailedCounter prometheus.Counter
) )
//nolint:promlinter //no idea to fix it
func NewUserLoginCounter() { func NewUserLoginCounter() {
if UserLoginCounter != nil { if UserLoginCounter != nil {
return return
@ -89,6 +90,7 @@ func NewUserLoginCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewUserRegisterCounter() { func NewUserRegisterCounter() {
if UserRegisterCounter != nil { if UserRegisterCounter != nil {
return return
@ -99,6 +101,7 @@ func NewUserRegisterCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewSeqGetSuccessCounter() { func NewSeqGetSuccessCounter() {
if SeqGetSuccessCounter != nil { if SeqGetSuccessCounter != nil {
return return
@ -109,6 +112,7 @@ func NewSeqGetSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewSeqGetFailedCounter() { func NewSeqGetFailedCounter() {
if SeqGetFailedCounter != nil { if SeqGetFailedCounter != nil {
return return
@ -119,6 +123,7 @@ func NewSeqGetFailedCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewSeqSetSuccessCounter() { func NewSeqSetSuccessCounter() {
if SeqSetSuccessCounter != nil { if SeqSetSuccessCounter != nil {
return return
@ -129,6 +134,7 @@ func NewSeqSetSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewSeqSetFailedCounter() { func NewSeqSetFailedCounter() {
if SeqSetFailedCounter != nil { if SeqSetFailedCounter != nil {
return return
@ -139,6 +145,7 @@ func NewSeqSetFailedCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewApiRequestCounter() { func NewApiRequestCounter() {
if ApiRequestCounter != nil { if ApiRequestCounter != nil {
return return
@ -149,6 +156,7 @@ func NewApiRequestCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewApiRequestSuccessCounter() { func NewApiRequestSuccessCounter() {
if ApiRequestSuccessCounter != nil { if ApiRequestSuccessCounter != nil {
return return
@ -159,6 +167,7 @@ func NewApiRequestSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewApiRequestFailedCounter() { func NewApiRequestFailedCounter() {
if ApiRequestFailedCounter != nil { if ApiRequestFailedCounter != nil {
return return
@ -169,6 +178,7 @@ func NewApiRequestFailedCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewGrpcRequestCounter() { func NewGrpcRequestCounter() {
if GrpcRequestCounter != nil { if GrpcRequestCounter != nil {
return return
@ -179,6 +189,7 @@ func NewGrpcRequestCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewGrpcRequestSuccessCounter() { func NewGrpcRequestSuccessCounter() {
if GrpcRequestSuccessCounter != nil { if GrpcRequestSuccessCounter != nil {
return return
@ -189,6 +200,7 @@ func NewGrpcRequestSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewGrpcRequestFailedCounter() { func NewGrpcRequestFailedCounter() {
if GrpcRequestFailedCounter != nil { if GrpcRequestFailedCounter != nil {
return return
@ -199,6 +211,7 @@ func NewGrpcRequestFailedCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewSendMsgCount() { func NewSendMsgCount() {
if SendMsgCounter != nil { if SendMsgCounter != nil {
return return
@ -209,6 +222,7 @@ func NewSendMsgCount() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewMsgInsertRedisSuccessCounter() { func NewMsgInsertRedisSuccessCounter() {
if MsgInsertRedisSuccessCounter != nil { if MsgInsertRedisSuccessCounter != nil {
return return
@ -219,6 +233,7 @@ func NewMsgInsertRedisSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix its
func NewMsgInsertRedisFailedCounter() { func NewMsgInsertRedisFailedCounter() {
if MsgInsertRedisFailedCounter != nil { if MsgInsertRedisFailedCounter != nil {
return return
@ -229,6 +244,7 @@ func NewMsgInsertRedisFailedCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewMsgInsertMongoSuccessCounter() { func NewMsgInsertMongoSuccessCounter() {
if MsgInsertMongoSuccessCounter != nil { if MsgInsertMongoSuccessCounter != nil {
return return
@ -239,6 +255,7 @@ func NewMsgInsertMongoSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewMsgInsertMongoFailedCounter() { func NewMsgInsertMongoFailedCounter() {
if MsgInsertMongoFailedCounter != nil { if MsgInsertMongoFailedCounter != nil {
return return
@ -249,6 +266,7 @@ func NewMsgInsertMongoFailedCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewMsgPullFromRedisSuccessCounter() { func NewMsgPullFromRedisSuccessCounter() {
if MsgPullFromRedisSuccessCounter != nil { if MsgPullFromRedisSuccessCounter != nil {
return return
@ -259,6 +277,7 @@ func NewMsgPullFromRedisSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewMsgPullFromRedisFailedCounter() { func NewMsgPullFromRedisFailedCounter() {
if MsgPullFromRedisFailedCounter != nil { if MsgPullFromRedisFailedCounter != nil {
return return
@ -269,6 +288,7 @@ func NewMsgPullFromRedisFailedCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewMsgPullFromMongoSuccessCounter() { func NewMsgPullFromMongoSuccessCounter() {
if MsgPullFromMongoSuccessCounter != nil { if MsgPullFromMongoSuccessCounter != nil {
return return
@ -279,6 +299,7 @@ func NewMsgPullFromMongoSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewMsgPullFromMongoFailedCounter() { func NewMsgPullFromMongoFailedCounter() {
if MsgPullFromMongoFailedCounter != nil { if MsgPullFromMongoFailedCounter != nil {
return return
@ -319,6 +340,7 @@ func NewPullMsgBySeqListTotalCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewSingleChatMsgRecvSuccessCounter() { func NewSingleChatMsgRecvSuccessCounter() {
if SingleChatMsgRecvSuccessCounter != nil { if SingleChatMsgRecvSuccessCounter != nil {
return return
@ -329,6 +351,7 @@ func NewSingleChatMsgRecvSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewGroupChatMsgRecvSuccessCounter() { func NewGroupChatMsgRecvSuccessCounter() {
if GroupChatMsgRecvSuccessCounter != nil { if GroupChatMsgRecvSuccessCounter != nil {
return return
@ -339,6 +362,7 @@ func NewGroupChatMsgRecvSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewWorkSuperGroupChatMsgRecvSuccessCounter() { func NewWorkSuperGroupChatMsgRecvSuccessCounter() {
if WorkSuperGroupChatMsgRecvSuccessCounter != nil { if WorkSuperGroupChatMsgRecvSuccessCounter != nil {
return return
@ -359,6 +383,7 @@ func NewOnlineUserGauges() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewSingleChatMsgProcessSuccessCounter() { func NewSingleChatMsgProcessSuccessCounter() {
if SingleChatMsgProcessSuccessCounter != nil { if SingleChatMsgProcessSuccessCounter != nil {
return return
@ -369,6 +394,7 @@ func NewSingleChatMsgProcessSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewSingleChatMsgProcessFailedCounter() { func NewSingleChatMsgProcessFailedCounter() {
if SingleChatMsgProcessFailedCounter != nil { if SingleChatMsgProcessFailedCounter != nil {
return return
@ -379,6 +405,7 @@ func NewSingleChatMsgProcessFailedCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewGroupChatMsgProcessSuccessCounter() { func NewGroupChatMsgProcessSuccessCounter() {
if GroupChatMsgProcessSuccessCounter != nil { if GroupChatMsgProcessSuccessCounter != nil {
return return
@ -389,6 +416,7 @@ func NewGroupChatMsgProcessSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewGroupChatMsgProcessFailedCounter() { func NewGroupChatMsgProcessFailedCounter() {
if GroupChatMsgProcessFailedCounter != nil { if GroupChatMsgProcessFailedCounter != nil {
return return
@ -399,6 +427,7 @@ func NewGroupChatMsgProcessFailedCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewWorkSuperGroupChatMsgProcessSuccessCounter() { func NewWorkSuperGroupChatMsgProcessSuccessCounter() {
if WorkSuperGroupChatMsgProcessSuccessCounter != nil { if WorkSuperGroupChatMsgProcessSuccessCounter != nil {
return return
@ -409,6 +438,7 @@ func NewWorkSuperGroupChatMsgProcessSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewWorkSuperGroupChatMsgProcessFailedCounter() { func NewWorkSuperGroupChatMsgProcessFailedCounter() {
if WorkSuperGroupChatMsgProcessFailedCounter != nil { if WorkSuperGroupChatMsgProcessFailedCounter != nil {
return return
@ -419,6 +449,7 @@ func NewWorkSuperGroupChatMsgProcessFailedCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewMsgOnlinePushSuccessCounter() { func NewMsgOnlinePushSuccessCounter() {
if MsgOnlinePushSuccessCounter != nil { if MsgOnlinePushSuccessCounter != nil {
return return
@ -429,6 +460,7 @@ func NewMsgOnlinePushSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewMsgOfflinePushSuccessCounter() { func NewMsgOfflinePushSuccessCounter() {
if MsgOfflinePushSuccessCounter != nil { if MsgOfflinePushSuccessCounter != nil {
return return
@ -439,6 +471,7 @@ func NewMsgOfflinePushSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewMsgOfflinePushFailedCounter() { func NewMsgOfflinePushFailedCounter() {
if MsgOfflinePushFailedCounter != nil { if MsgOfflinePushFailedCounter != nil {
return return
@ -449,6 +482,7 @@ func NewMsgOfflinePushFailedCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewConversationCreateSuccessCounter() { func NewConversationCreateSuccessCounter() {
if ConversationCreateSuccessCounter != nil { if ConversationCreateSuccessCounter != nil {
return return
@ -459,6 +493,7 @@ func NewConversationCreateSuccessCounter() {
}) })
} }
//nolint:promlinter //no idea to fix it
func NewConversationCreateFailedCounter() { func NewConversationCreateFailedCounter() {
if ConversationCreateFailedCounter != nil { if ConversationCreateFailedCounter != nil {
return return

@ -30,13 +30,16 @@ func StartPrometheusSrv(prometheusPort int) error {
if config.Config.Prometheus.Enable { if config.Config.Prometheus.Enable {
http.Handle("/metrics", promhttp.Handler()) http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(":"+strconv.Itoa(prometheusPort), nil) err := http.ListenAndServe(":"+strconv.Itoa(prometheusPort), nil)
return err return err
} }
return nil return nil
} }
func PrometheusHandler() gin.HandlerFunc { func PrometheusHandler() gin.HandlerFunc {
h := promhttp.Handler() h := promhttp.Handler()
return func(c *gin.Context) { return func(c *gin.Context) {
h.ServeHTTP(c.Writer, c.Request) h.ServeHTTP(c.Writer, c.Request)
} }
@ -49,6 +52,7 @@ type responseBodyWriter struct {
func (r responseBodyWriter) Write(b []byte) (int, error) { func (r responseBodyWriter) Write(b []byte) (int, error) {
r.body.Write(b) r.body.Write(b)
return r.ResponseWriter.Write(b) return r.ResponseWriter.Write(b)
} }

@ -24,6 +24,7 @@ import (
"github.com/openimsdk/open-im-server/v3/pkg/common/config" "github.com/openimsdk/open-im-server/v3/pkg/common/config"
) )
//nolint:staticcheck //we have not time looking for a replacement for x509 to fix the security valnerability
func decryptPEM(data []byte, passphrase []byte) ([]byte, error) { func decryptPEM(data []byte, passphrase []byte) ([]byte, error) {
if len(passphrase) == 0 { if len(passphrase) == 0 {
return data, nil return data, nil
@ -33,6 +34,7 @@ func decryptPEM(data []byte, passphrase []byte) ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return pem.EncodeToMemory(&pem.Block{ return pem.EncodeToMemory(&pem.Block{
Type: b.Type, Type: b.Type,
Bytes: d, Bytes: d,
@ -44,6 +46,7 @@ func readEncryptablePEMBlock(path string, pwd []byte) ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return decryptPEM(data, pwd) return decryptPEM(data, pwd)
} }

@ -28,6 +28,7 @@ func GetNotificationConversationIDByMsg(msg *sdkws.MsgData) string {
case constant.SingleChatType: case constant.SingleChatType:
l := []string{msg.SendID, msg.RecvID} l := []string{msg.SendID, msg.RecvID}
sort.Strings(l) sort.Strings(l)
return "n_" + strings.Join(l, "_") return "n_" + strings.Join(l, "_")
case constant.GroupChatType: case constant.GroupChatType:
return "n_" + msg.GroupID return "n_" + msg.GroupID
@ -36,6 +37,7 @@ func GetNotificationConversationIDByMsg(msg *sdkws.MsgData) string {
case constant.NotificationChatType: case constant.NotificationChatType:
return "n_" + msg.SendID + "_" + msg.RecvID return "n_" + msg.SendID + "_" + msg.RecvID
} }
return "" return ""
} }
@ -44,6 +46,7 @@ func GetChatConversationIDByMsg(msg *sdkws.MsgData) string {
case constant.SingleChatType: case constant.SingleChatType:
l := []string{msg.SendID, msg.RecvID} l := []string{msg.SendID, msg.RecvID}
sort.Strings(l) sort.Strings(l)
return "si_" + strings.Join(l, "_") return "si_" + strings.Join(l, "_")
case constant.GroupChatType: case constant.GroupChatType:
return "g_" + msg.GroupID return "g_" + msg.GroupID
@ -52,6 +55,7 @@ func GetChatConversationIDByMsg(msg *sdkws.MsgData) string {
case constant.NotificationChatType: case constant.NotificationChatType:
return "sn_" + msg.SendID + "_" + msg.RecvID return "sn_" + msg.SendID + "_" + msg.RecvID
} }
return "" return ""
} }
@ -60,10 +64,12 @@ func GenConversationUniqueKey(msg *sdkws.MsgData) string {
case constant.SingleChatType, constant.NotificationChatType: case constant.SingleChatType, constant.NotificationChatType:
l := []string{msg.SendID, msg.RecvID} l := []string{msg.SendID, msg.RecvID}
sort.Strings(l) sort.Strings(l)
return strings.Join(l, "_") return strings.Join(l, "_")
case constant.SuperGroupChatType: case constant.SuperGroupChatType:
return msg.GroupID return msg.GroupID
} }
return "" return ""
} }
@ -76,23 +82,28 @@ func GetConversationIDByMsg(msg *sdkws.MsgData) string {
if !options.IsNotNotification() { if !options.IsNotNotification() {
return "n_" + strings.Join(l, "_") return "n_" + strings.Join(l, "_")
} }
return "si_" + strings.Join(l, "_") // single chat return "si_" + strings.Join(l, "_") // single chat
case constant.GroupChatType: case constant.GroupChatType:
if !options.IsNotNotification() { if !options.IsNotNotification() {
return "n_" + msg.GroupID // group chat return "n_" + msg.GroupID // group chat
} }
return "g_" + msg.GroupID // group chat return "g_" + msg.GroupID // group chat
case constant.SuperGroupChatType: case constant.SuperGroupChatType:
if !options.IsNotNotification() { if !options.IsNotNotification() {
return "n_" + msg.GroupID // super group chat return "n_" + msg.GroupID // super group chat
} }
return "sg_" + msg.GroupID // super group chat return "sg_" + msg.GroupID // super group chat
case constant.NotificationChatType: case constant.NotificationChatType:
if !options.IsNotNotification() { if !options.IsNotNotification() {
return "n_" + msg.SendID + "_" + msg.RecvID // super group chat return "n_" + msg.SendID + "_" + msg.RecvID // super group chat
} }
return "sn_" + msg.SendID + "_" + msg.RecvID // server notification chat return "sn_" + msg.SendID + "_" + msg.RecvID // server notification chat
} }
return "" return ""
} }
@ -111,6 +122,7 @@ func GetConversationIDBySessionType(sessionType int, ids ...string) string {
case constant.NotificationChatType: case constant.NotificationChatType:
return "sn_" + ids[0] // server notification chat return "sn_" + ids[0] // server notification chat
} }
return "" return ""
} }
@ -118,10 +130,11 @@ func GetNotificationConversationIDByConversationID(conversationID string) string
l := strings.Split(conversationID, "_") l := strings.Split(conversationID, "_")
if len(l) > 1 { if len(l) > 1 {
l[0] = "n" l[0] = "n"
return strings.Join(l, "_") return strings.Join(l, "_")
} else {
return ""
} }
return ""
} }
func GetNotificationConversationID(sessionType int, ids ...string) string { func GetNotificationConversationID(sessionType int, ids ...string) string {
@ -135,6 +148,7 @@ func GetNotificationConversationID(sessionType int, ids ...string) string {
case constant.SuperGroupChatType: case constant.SuperGroupChatType:
return "n_" + ids[0] // super group chat return "n_" + ids[0] // super group chat
} }
return "" return ""
} }
@ -155,18 +169,22 @@ func ParseConversationID(msg *sdkws.MsgData) (isNotification bool, conversationI
if !options.IsNotNotification() { if !options.IsNotNotification() {
return true, "n_" + strings.Join(l, "_") return true, "n_" + strings.Join(l, "_")
} }
return false, "si_" + strings.Join(l, "_") // single chat return false, "si_" + strings.Join(l, "_") // single chat
case constant.SuperGroupChatType: case constant.SuperGroupChatType:
if !options.IsNotNotification() { if !options.IsNotNotification() {
return true, "n_" + msg.GroupID // super group chat return true, "n_" + msg.GroupID // super group chat
} }
return false, "sg_" + msg.GroupID // super group chat return false, "sg_" + msg.GroupID // super group chat
case constant.NotificationChatType: case constant.NotificationChatType:
if !options.IsNotNotification() { if !options.IsNotNotification() {
return true, "n_" + msg.SendID + "_" + msg.RecvID // super group chat return true, "n_" + msg.SendID + "_" + msg.RecvID // super group chat
} }
return false, "sn_" + msg.SendID + "_" + msg.RecvID // server notification chat return false, "sn_" + msg.SendID + "_" + msg.RecvID // server notification chat
} }
return false, "" return false, ""
} }
@ -189,6 +207,7 @@ func Pb2String(pb proto.Message) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
return string(s), nil return string(s), nil
} }

@ -38,12 +38,14 @@ func NewOptions(opts ...OptionsOpt) Options {
for _, opt := range opts { for _, opt := range opts {
opt(options) opt(options)
} }
return options return options
} }
func NewMsgOptions() Options { func NewMsgOptions() Options {
options := make(map[string]bool, 11) options := make(map[string]bool, 11)
options[constant.IsOfflinePush] = false options[constant.IsOfflinePush] = false
return make(map[string]bool) return make(map[string]bool)
} }
@ -51,6 +53,7 @@ func WithOptions(options Options, opts ...OptionsOpt) Options {
for _, opt := range opts { for _, opt := range opts {
opt(options) opt(options)
} }
return options return options
} }
@ -131,6 +134,7 @@ func (o Options) Is(notification string) bool {
if !ok || v { if !ok || v {
return true return true
} }
return false return false
} }

Loading…
Cancel
Save