From fdcca9600087ed6226d4dd9e0f339fc51bb67c42 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Tue, 25 Jul 2023 17:13:22 +0800 Subject: [PATCH] chore: replacement package Signed-off-by: withchao <993506633@qq.com> --- cmd/openim-api/main.go | 4 +- go.mod | 21 +- go.sum | 2 - internal/api/route.go | 71 +++- internal/msgtransfer/init.go | 2 +- internal/push/callback.go | 6 +- internal/push/offlinepush/fcm/push.go | 3 +- internal/push/offlinepush/getui/push.go | 2 +- internal/push/tools.go | 18 + internal/rpc/friend/friend.go | 9 +- internal/rpc/msg/callback.go | 15 +- pkg/common/cmd/root.go | 3 +- pkg/common/config/config.go | 312 ------------------ pkg/common/config/parse.go | 55 +--- pkg/common/constant/constant.go | 363 --------------------- pkg/common/constant/limit.go | 21 -- pkg/common/constant/platform_id_to_name.go | 109 ------- 17 files changed, 145 insertions(+), 871 deletions(-) create mode 100644 internal/push/tools.go delete mode 100644 pkg/common/config/config.go delete mode 100644 pkg/common/constant/constant.go delete mode 100644 pkg/common/constant/limit.go delete mode 100644 pkg/common/constant/platform_id_to_name.go diff --git a/cmd/openim-api/main.go b/cmd/openim-api/main.go index 925ea4045..c967906e9 100644 --- a/cmd/openim-api/main.go +++ b/cmd/openim-api/main.go @@ -73,11 +73,11 @@ func run(port int) error { if err != nil { return err } - if err := client.CreateRpcRootNodes(config.GetServiceNames()); err != nil { + if err := client.CreateRpcRootNodes(config.Config.GetServiceNames()); err != nil { return err } fmt.Println("api register public config to discov") - if err := client.RegisterConf2Registry(constant.OpenIMCommonConfigKey, config.EncodeConfig()); err != nil { + if err := client.RegisterConf2Registry(constant.OpenIMCommonConfigKey, config.Config.EncodeConfig()); err != nil { return err } fmt.Println("api register public config to discov success") diff --git a/go.mod b/go.mod index f737a3a09..75f3f3e03 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,8 @@ go 1.18 require ( firebase.google.com/go v3.13.0+incompatible - github.com/OpenIMSDK/open_utils v1.0.8 github.com/Shopify/sarama v1.29.0 - github.com/bwmarrin/snowflake v0.3.0 + github.com/bwmarrin/snowflake v0.3.0 // indirect github.com/dtm-labs/rockscache v0.1.1 github.com/gin-gonic/gin v1.9.1 github.com/go-playground/validator/v10 v10.14.0 @@ -14,19 +13,19 @@ require ( github.com/golang-jwt/jwt/v4 v4.5.0 github.com/golang/protobuf v1.5.3 github.com/gorilla/websocket v1.4.2 - github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 + github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/jinzhu/copier v0.3.5 - github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible + github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect github.com/minio/minio-go/v7 v7.0.59 github.com/mitchellh/mapstructure v1.5.0 - github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 - github.com/pkg/errors v0.9.1 + github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_golang v1.16.0 github.com/robfig/cron/v3 v3.0.1 github.com/sirupsen/logrus v1.9.2 // indirect github.com/stretchr/testify v1.8.3 go.mongodb.org/mongo-driver v1.12.0 - golang.org/x/image v0.9.0 + golang.org/x/image v0.9.0 // indirect google.golang.org/api v0.114.0 google.golang.org/grpc v1.56.2 google.golang.org/protobuf v1.31.0 @@ -39,11 +38,10 @@ require github.com/google/uuid v1.3.0 require ( github.com/OpenIMSDK/protocol v0.0.0-20230725064305-11f0568fe5e9 - github.com/OpenIMSDK/tools v0.0.0-20230725065329-f1a0cb3b07ac + github.com/OpenIMSDK/tools v0.0.0-20230725085302-133df5f2ea13 github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible github.com/go-redis/redis v6.15.9+incompatible github.com/go-sql-driver/mysql v1.6.0 - github.com/go-zookeeper/zk v1.0.3 github.com/redis/go-redis/v9 v9.0.5 github.com/tencentyun/cos-go-sdk-v5 v0.7.41 ) @@ -70,6 +68,7 @@ require ( github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-zookeeper/zk v1.0.3 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/snappy v0.0.3 // indirect github.com/google/go-cmp v0.5.9 // indirect @@ -136,8 +135,10 @@ require ( github.com/mattn/go-isatty v0.0.19 // indirect github.com/spf13/cobra v1.6.1 github.com/ugorji/go/codec v1.2.11 // indirect - go.uber.org/zap v1.24.0 + go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.10.0 // indirect google.golang.org/genproto v0.0.0-20230525234025-438c736192d0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect ) + +replace github.com/OpenIMSDK/tools => C:\Users\Admin\Desktop\openim\tools diff --git a/go.sum b/go.sum index f74f8105f..db8bf3183 100644 --- a/go.sum +++ b/go.sum @@ -16,8 +16,6 @@ cloud.google.com/go/storage v1.28.1/go.mod h1:Qnisd4CqDdo6BGs2AD5LLnEsmSQ80wQ5og firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4= firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/OpenIMSDK/open_utils v1.0.8 h1:IopxWgJwEF5ZAPsRuiZZOfcxNOQOCt/p8VDENcHN9r4= -github.com/OpenIMSDK/open_utils v1.0.8/go.mod h1:FLoaQblWUVKQgqt2LrNzfSZLT6D3DICBn1kcOMDLUOI= github.com/OpenIMSDK/protocol v0.0.0-20230725064305-11f0568fe5e9 h1:ZtW+z2j2kjk51awH9OFRXbgNI5Vcfq0Lu9//ax86ktc= github.com/OpenIMSDK/protocol v0.0.0-20230725064305-11f0568fe5e9/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= github.com/OpenIMSDK/tools v0.0.0-20230725065329-f1a0cb3b07ac h1:s+mvgvDVZY/AI0GIWGb0eQOy2zFTlUsCOBiHY7uWDvY= diff --git a/internal/api/route.go b/internal/api/route.go index bc69ff8b3..453224263 100644 --- a/internal/api/route.go +++ b/internal/api/route.go @@ -16,6 +16,13 @@ package api import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" + "github.com/OpenIMSDK/tools/apiresp" + "github.com/OpenIMSDK/tools/constant" + "github.com/OpenIMSDK/tools/errs" + "github.com/OpenIMSDK/tools/tokenverify" + "net/http" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" @@ -59,7 +66,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive r.Use(prome.PrometheusMiddleware) r.GET("/metrics", prome.PrometheusHandler()) } - ParseToken := mw.GinParseToken(rdb) + ParseToken := GinParseToken(rdb) userRouterGroup := r.Group("/user") { userRouterGroup.POST("/user_register", u.UserRegister) @@ -186,3 +193,65 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive } return r } + +func GinParseToken(rdb redis.UniversalClient) gin.HandlerFunc { + dataBase := controller.NewAuthDatabase( + cache.NewMsgCacheModel(rdb), + config.Config.Secret, + config.Config.TokenPolicy.Expire, + ) + return func(c *gin.Context) { + switch c.Request.Method { + case http.MethodPost: + token := c.Request.Header.Get(constant.Token) + if token == "" { + log.ZWarn(c, "header get token error", errs.ErrArgs.Wrap("header must have token")) + apiresp.GinError(c, errs.ErrArgs.Wrap("header must have token")) + c.Abort() + return + } + claims, err := tokenverify.GetClaimFromToken(token) + if err != nil { + log.ZWarn(c, "jwt get token error", errs.ErrTokenUnknown.Wrap()) + apiresp.GinError(c, errs.ErrTokenUnknown.Wrap()) + c.Abort() + return + } + m, err := dataBase.GetTokensWithoutError(c, claims.UserID, claims.PlatformID) + if err != nil { + log.ZWarn(c, "cache get token error", errs.ErrTokenNotExist.Wrap()) + apiresp.GinError(c, errs.ErrTokenNotExist.Wrap()) + c.Abort() + return + } + if len(m) == 0 { + log.ZWarn(c, "cache do not exist token error", errs.ErrTokenNotExist.Wrap()) + apiresp.GinError(c, errs.ErrTokenNotExist.Wrap()) + c.Abort() + return + } + if v, ok := m[token]; ok { + switch v { + case constant.NormalToken: + case constant.KickedToken: + log.ZWarn(c, "cache kicked token error", errs.ErrTokenKicked.Wrap()) + apiresp.GinError(c, errs.ErrTokenKicked.Wrap()) + c.Abort() + return + default: + log.ZWarn(c, "cache unknown token error", errs.ErrTokenUnknown.Wrap()) + apiresp.GinError(c, errs.ErrTokenUnknown.Wrap()) + c.Abort() + return + } + } else { + apiresp.GinError(c, errs.ErrTokenNotExist.Wrap()) + c.Abort() + return + } + c.Set(constant.OpUserPlatform, constant.PlatformIDToName(claims.PlatformID)) + c.Set(constant.OpUserID, claims.UserID) + c.Next() + } + } +} diff --git a/internal/msgtransfer/init.go b/internal/msgtransfer/init.go index 53c1dfcab..037564f7a 100644 --- a/internal/msgtransfer/init.go +++ b/internal/msgtransfer/init.go @@ -67,7 +67,7 @@ func StartTransfer(prometheusPort int) error { if err != nil { return err } - if client.CreateRpcRootNodes(config.GetServiceNames()); err != nil { + if err := client.CreateRpcRootNodes(config.Config.GetServiceNames()); err != nil { return err } client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) diff --git a/internal/push/callback.go b/internal/push/callback.go index 9264df22a..bbc392a6e 100644 --- a/internal/push/callback.go +++ b/internal/push/callback.go @@ -57,7 +57,7 @@ func callbackOfflinePush( ContentType: msg.ContentType, SessionType: msg.SessionType, AtUserIDs: msg.AtUserIDList, - Content: utils.GetContent(msg), + Content: GetContent(msg), } resp := &callbackstruct.CallbackBeforePushResp{} if err := http.CallBackPostReturn(ctx, url(), req, resp, config.Config.Callback.CallbackOfflinePush); err != nil { @@ -95,7 +95,7 @@ func callbackOnlinePush(ctx context.Context, userIDs []string, msg *sdkws.MsgDat ContentType: msg.ContentType, SessionType: msg.SessionType, AtUserIDs: msg.AtUserIDList, - Content: utils.GetContent(msg), + Content: GetContent(msg), } resp := &callbackstruct.CallbackBeforePushResp{} return http.CallBackPostReturn(ctx, url(), req, resp, config.Config.Callback.CallbackOnlinePush) @@ -123,7 +123,7 @@ func callbackBeforeSuperGroupOnlinePush( ContentType: msg.ContentType, SessionType: msg.SessionType, AtUserIDs: msg.AtUserIDList, - Content: utils.GetContent(msg), + Content: GetContent(msg), Seq: msg.Seq, } resp := &callbackstruct.CallbackBeforeSuperGroupOnlinePushResp{} diff --git a/internal/push/offlinepush/fcm/push.go b/internal/push/offlinepush/fcm/push.go index 1f519a523..8f29f0258 100644 --- a/internal/push/offlinepush/fcm/push.go +++ b/internal/push/offlinepush/fcm/push.go @@ -16,6 +16,7 @@ package fcm import ( "context" + config2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "path/filepath" firebase "firebase.google.com/go" @@ -39,7 +40,7 @@ type Fcm struct { } func NewClient(cache cache.MsgModel) *Fcm { - opt := option.WithCredentialsFile(filepath.Join(config.Root, "config", config.Config.Push.Fcm.ServiceAccount)) + opt := option.WithCredentialsFile(filepath.Join(config2.Root, "config", config.Config.Push.Fcm.ServiceAccount)) fcmApp, err := firebase.NewApp(context.Background(), nil, opt) if err != nil { return nil diff --git a/internal/push/offlinepush/getui/push.go b/internal/push/offlinepush/getui/push.go index 670874da7..b440ef71b 100644 --- a/internal/push/offlinepush/getui/push.go +++ b/internal/push/offlinepush/getui/push.go @@ -28,11 +28,11 @@ import ( "github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" http2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" - "github.com/OpenIMSDK/Open-IM-Server/pkg/utils/splitter" "github.com/OpenIMSDK/tools/config" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/mcontext" + "github.com/OpenIMSDK/tools/utils/splitter" "github.com/OpenIMSDK/tools/utils" ) diff --git a/internal/push/tools.go b/internal/push/tools.go new file mode 100644 index 000000000..ea8d160b1 --- /dev/null +++ b/internal/push/tools.go @@ -0,0 +1,18 @@ +package push + +import ( + "github.com/OpenIMSDK/protocol/sdkws" + "github.com/OpenIMSDK/tools/constant" + "google.golang.org/protobuf/proto" +) + +func GetContent(msg *sdkws.MsgData) string { + if msg.ContentType >= constant.NotificationBegin && msg.ContentType <= constant.NotificationEnd { + var tips sdkws.TipsComm + _ = proto.Unmarshal(msg.Content, &tips) + content := tips.JsonDetail + return content + } else { + return string(msg.Content) + } +} diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index de3c398c6..5792fdb38 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -254,8 +254,7 @@ func (s *friendServer) GetPaginationFriendsApplyTo( if err := s.userRpcClient.Access(ctx, req.UserID); err != nil { return nil, err } - pageNumber, showNumber := utils.GetPage(req.Pagination) - friendRequests, total, err := s.friendDatabase.PageFriendRequestToMe(ctx, req.UserID, pageNumber, showNumber) + friendRequests, total, err := s.friendDatabase.PageFriendRequestToMe(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber) if err != nil { return nil, err } @@ -278,8 +277,7 @@ func (s *friendServer) GetPaginationFriendsApplyFrom( if err := s.userRpcClient.Access(ctx, req.UserID); err != nil { return nil, err } - pageNumber, showNumber := utils.GetPage(req.Pagination) - friendRequests, total, err := s.friendDatabase.PageFriendRequestFromMe(ctx, req.UserID, pageNumber, showNumber) + friendRequests, total, err := s.friendDatabase.PageFriendRequestFromMe(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber) if err != nil { return nil, err } @@ -314,8 +312,7 @@ func (s *friendServer) GetPaginationFriends( if err := s.userRpcClient.Access(ctx, req.UserID); err != nil { return nil, err } - pageNumber, showNumber := utils.GetPage(req.Pagination) - friends, total, err := s.friendDatabase.PageOwnerFriends(ctx, req.UserID, pageNumber, showNumber) + friends, total, err := s.friendDatabase.PageOwnerFriends(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber) if err != nil { return nil, err } diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 52662ace2..47bd1f0f1 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -16,6 +16,8 @@ package msg import ( "context" + "github.com/OpenIMSDK/protocol/sdkws" + "google.golang.org/protobuf/proto" cbapi "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" @@ -48,12 +50,23 @@ func toCommonCallback(ctx context.Context, msg *pbChat.SendMsgReq, command strin CreateTime: msg.MsgData.CreateTime, AtUserIDList: msg.MsgData.AtUserIDList, SenderFaceURL: msg.MsgData.SenderFaceURL, - Content: utils.GetContent(msg.MsgData), + Content: GetContent(msg.MsgData), Seq: uint32(msg.MsgData.Seq), Ex: msg.MsgData.Ex, } } +func GetContent(msg *sdkws.MsgData) string { + if msg.ContentType >= constant.NotificationBegin && msg.ContentType <= constant.NotificationEnd { + var tips sdkws.TipsComm + _ = proto.Unmarshal(msg.Content, &tips) + content := tips.JsonDetail + return content + } else { + return string(msg.Content) + } +} + func callbackBeforeSendSingleMsg(ctx context.Context, msg *pbChat.SendMsgReq) error { if !config.Config.Callback.CallbackBeforeSendSingleMsg.Enable { return nil diff --git a/pkg/common/cmd/root.go b/pkg/common/cmd/root.go index 80a9aebee..718d9bf7b 100644 --- a/pkg/common/cmd/root.go +++ b/pkg/common/cmd/root.go @@ -16,6 +16,7 @@ package cmd import ( "fmt" + config2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/spf13/cobra" @@ -108,7 +109,7 @@ func (r *RootCmd) GetPrometheusPortFlag() int { func (r *RootCmd) getConfFromCmdAndInit(cmdLines *cobra.Command) error { configFolderPath, _ := cmdLines.Flags().GetString(constant.FlagConf) fmt.Println("configFolderPath:", configFolderPath) - return config.InitConfig(configFolderPath) + return config2.InitConfig(configFolderPath) } func (r *RootCmd) Execute() error { diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go deleted file mode 100644 index f9b2b9783..000000000 --- a/pkg/common/config/config.go +++ /dev/null @@ -1,312 +0,0 @@ -// Copyright © 2023 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -import ( - _ "embed" -) - -//go:embed version -var Version string - -var Config config - -type CallBackConfig struct { - Enable bool `yaml:"enable"` - CallbackTimeOut int `yaml:"timeout"` - CallbackFailedContinue *bool `yaml:"failedContinue"` -} - -type NotificationConf struct { - IsSendMsg bool `yaml:"isSendMsg"` - ReliabilityLevel int `yaml:"reliabilityLevel"` // 1 online 2 persistent - UnreadCount bool `yaml:"unreadCount"` - OfflinePush POfflinePush `yaml:"offlinePush"` -} - -type POfflinePush struct { - Enable bool `yaml:"enable"` - Title string `yaml:"title"` - Desc string `yaml:"desc"` - Ext string `yaml:"ext"` -} - -type config struct { - Zookeeper struct { - Schema string `yaml:"schema"` - ZkAddr []string `yaml:"address"` - Username string `yaml:"username"` - Password string `yaml:"password"` - } `yaml:"zookeeper"` - - Mysql struct { - Address []string `yaml:"address"` - Username string `yaml:"username"` - Password string `yaml:"password"` - Database string `yaml:"database"` - MaxOpenConn int `yaml:"maxOpenConn"` - MaxIdleConn int `yaml:"maxIdleConn"` - MaxLifeTime int `yaml:"maxLifeTime"` - LogLevel int `yaml:"logLevel"` - SlowThreshold int `yaml:"slowThreshold"` - } `yaml:"mysql"` - - Mongo struct { - Uri string `yaml:"uri"` - Address []string `yaml:"address"` - Database string `yaml:"database"` - Username string `yaml:"username"` - Password string `yaml:"password"` - MaxPoolSize int `yaml:"maxPoolSize"` - } `yaml:"mongo"` - - Redis struct { - Address []string `yaml:"address"` - Username string `yaml:"username"` - Password string `yaml:"password"` - } `yaml:"redis"` - - Kafka struct { - Username string `yaml:"username"` - Password string `yaml:"password"` - Addr []string `yaml:"addr"` - LatestMsgToRedis struct { - Topic string `yaml:"topic"` - } `yaml:"latestMsgToRedis"` - MsgToMongo struct { - Topic string `yaml:"topic"` - } `yaml:"offlineMsgToMongo"` - MsgToPush struct { - Topic string `yaml:"topic"` - } `yaml:"msgToPush"` - ConsumerGroupID struct { - MsgToRedis string `yaml:"msgToRedis"` - MsgToMongo string `yaml:"msgToMongo"` - MsgToMySql string `yaml:"msgToMySql"` - MsgToPush string `yaml:"msgToPush"` - } `yaml:"consumerGroupID"` - } `yaml:"kafka"` - - Rpc struct { - RegisterIP string `yaml:"registerIP"` - ListenIP string `yaml:"listenIP"` - } `yaml:"rpc"` - - Api struct { - OpenImApiPort []int `yaml:"openImApiPort"` - ListenIP string `yaml:"listenIP"` - } `yaml:"api"` - - Object struct { - Enable string `yaml:"enable"` - ApiURL string `yaml:"apiURL"` - Minio struct { - Bucket string `yaml:"bucket"` - Endpoint string `yaml:"endpoint"` - AccessKeyID string `yaml:"accessKeyID"` - SecretAccessKey string `yaml:"secretAccessKey"` - SessionToken string `yaml:"sessionToken"` - } `yaml:"minio"` - Cos struct { - BucketURL string `yaml:"bucketURL"` - SecretID string `yaml:"secretID"` - SecretKey string `yaml:"secretKey"` - SessionToken string `yaml:"sessionToken"` - } `yaml:"cos"` - Oss struct { - Endpoint string `yaml:"endpoint"` - Bucket string `yaml:"bucket"` - BucketURL string `yaml:"bucketURL"` - AccessKeyID string `yaml:"accessKeyID"` - AccessKeySecret string `yaml:"accessKeySecret"` - SessionToken string `yaml:"sessionToken"` - } `yaml:"oss"` - } `yaml:"object"` - - RpcPort struct { - OpenImUserPort []int `yaml:"openImUserPort"` - OpenImFriendPort []int `yaml:"openImFriendPort"` - OpenImMessagePort []int `yaml:"openImMessagePort"` - OpenImMessageGatewayPort []int `yaml:"openImMessageGatewayPort"` - OpenImGroupPort []int `yaml:"openImGroupPort"` - OpenImAuthPort []int `yaml:"openImAuthPort"` - OpenImPushPort []int `yaml:"openImPushPort"` - OpenImConversationPort []int `yaml:"openImConversationPort"` - OpenImRtcPort []int `yaml:"openImRtcPort"` - OpenImThirdPort []int `yaml:"openImThirdPort"` - } `yaml:"rpcPort"` - - RpcRegisterName struct { - OpenImUserName string `yaml:"openImUserName"` - OpenImFriendName string `yaml:"openImFriendName"` - OpenImMsgName string `yaml:"openImMsgName"` - OpenImPushName string `yaml:"openImPushName"` - OpenImMessageGatewayName string `yaml:"openImMessageGatewayName"` - OpenImGroupName string `yaml:"openImGroupName"` - OpenImAuthName string `yaml:"openImAuthName"` - OpenImConversationName string `yaml:"openImConversationName"` - OpenImThirdName string `yaml:"openImThirdName"` - } `yaml:"rpcRegisterName"` - - Log struct { - StorageLocation string `yaml:"storageLocation"` - RotationTime int `yaml:"rotationTime"` - RemainRotationCount uint `yaml:"remainRotationCount"` - RemainLogLevel int `yaml:"remainLogLevel"` - IsStdout bool `yaml:"isStdout"` - IsJson bool `yaml:"isJson"` - WithStack bool `yaml:"withStack"` - } `yaml:"log"` - - LongConnSvr struct { - OpenImWsPort []int `yaml:"openImWsPort"` - WebsocketMaxConnNum int `yaml:"websocketMaxConnNum"` - WebsocketMaxMsgLen int `yaml:"websocketMaxMsgLen"` - WebsocketTimeout int `yaml:"websocketTimeout"` - } `yaml:"longConnSvr"` - - Push struct { - Enable string `yaml:"enable"` - GeTui struct { - PushUrl string `yaml:"pushUrl"` - AppKey string `yaml:"appKey"` - Intent string `yaml:"intent"` - MasterSecret string `yaml:"masterSecret"` - ChannelID string `yaml:"channelID"` - ChannelName string `yaml:"channelName"` - } `yaml:"geTui"` - Fcm struct { - ServiceAccount string `yaml:"serviceAccount"` - } `yaml:"fcm"` - Jpns struct { - AppKey string `yaml:"appKey"` - MasterSecret string `yaml:"masterSecret"` - PushUrl string `yaml:"pushUrl"` - PushIntent string `yaml:"pushIntent"` - } `yaml:"jpns"` - } - Manager struct { - UserID []string `yaml:"userID"` - Nickname []string `yaml:"nickname"` - } `yaml:"manager"` - - MultiLoginPolicy int `yaml:"multiLoginPolicy"` - ChatPersistenceMysql bool `yaml:"chatPersistenceMysql"` - MsgCacheTimeout int `yaml:"msgCacheTimeout"` - GroupMessageHasReadReceiptEnable bool `yaml:"groupMessageHasReadReceiptEnable"` - SingleMessageHasReadReceiptEnable bool `yaml:"singleMessageHasReadReceiptEnable"` - RetainChatRecords int `yaml:"retainChatRecords"` - ChatRecordsClearTime string `yaml:"chatRecordsClearTime"` - MsgDestructTime string `yaml:"msgDestructTime"` - Secret string `yaml:"secret"` - TokenPolicy struct { - Expire int64 `yaml:"expire"` - } `yaml:"tokenPolicy"` - MessageVerify struct { - FriendVerify *bool `yaml:"friendVerify"` - } `yaml:"messageVerify"` - - IOSPush struct { - PushSound string `yaml:"pushSound"` - BadgeCount bool `yaml:"badgeCount"` - Production bool `yaml:"production"` - } `yaml:"iosPush"` - Callback struct { - CallbackUrl string `yaml:"url"` - CallbackBeforeSendSingleMsg CallBackConfig `yaml:"beforeSendSingleMsg"` - CallbackAfterSendSingleMsg CallBackConfig `yaml:"afterSendSingleMsg"` - CallbackBeforeSendGroupMsg CallBackConfig `yaml:"beforeSendGroupMsg"` - CallbackAfterSendGroupMsg CallBackConfig `yaml:"afterSendGroupMsg"` - CallbackMsgModify CallBackConfig `yaml:"msgModify"` - CallbackUserOnline CallBackConfig `yaml:"userOnline"` - CallbackUserOffline CallBackConfig `yaml:"userOffline"` - CallbackUserKickOff CallBackConfig `yaml:"userKickOff"` - CallbackOfflinePush CallBackConfig `yaml:"offlinePush"` - CallbackOnlinePush CallBackConfig `yaml:"onlinePush"` - CallbackBeforeSuperGroupOnlinePush CallBackConfig `yaml:"superGroupOnlinePush"` - CallbackBeforeAddFriend CallBackConfig `yaml:"beforeAddFriend"` - CallbackBeforeCreateGroup CallBackConfig `yaml:"beforeCreateGroup"` - CallbackBeforeMemberJoinGroup CallBackConfig `yaml:"beforeMemberJoinGroup"` - CallbackBeforeSetGroupMemberInfo CallBackConfig `yaml:"beforeSetGroupMemberInfo"` - } `yaml:"callback"` - - Prometheus struct { - Enable bool `yaml:"enable"` - UserPrometheusPort []int `yaml:"userPrometheusPort"` - FriendPrometheusPort []int `yaml:"friendPrometheusPort"` - MessagePrometheusPort []int `yaml:"messagePrometheusPort"` - MessageGatewayPrometheusPort []int `yaml:"messageGatewayPrometheusPort"` - GroupPrometheusPort []int `yaml:"groupPrometheusPort"` - AuthPrometheusPort []int `yaml:"authPrometheusPort"` - PushPrometheusPort []int `yaml:"pushPrometheusPort"` - ConversationPrometheusPort []int `yaml:"conversationPrometheusPort"` - RtcPrometheusPort []int `yaml:"rtcPrometheusPort"` - MessageTransferPrometheusPort []int `yaml:"messageTransferPrometheusPort"` - ThirdPrometheusPort []int `yaml:"thirdPrometheusPort"` - } `yaml:"prometheus"` - Notification notification `yaml:"notification"` -} - -type notification struct { - GroupCreated NotificationConf `yaml:"groupCreated"` - GroupInfoSet NotificationConf `yaml:"groupInfoSet"` - JoinGroupApplication NotificationConf `yaml:"joinGroupApplication"` - MemberQuit NotificationConf `yaml:"memberQuit"` - GroupApplicationAccepted NotificationConf `yaml:"groupApplicationAccepted"` - GroupApplicationRejected NotificationConf `yaml:"groupApplicationRejected"` - GroupOwnerTransferred NotificationConf `yaml:"groupOwnerTransferred"` - MemberKicked NotificationConf `yaml:"memberKicked"` - MemberInvited NotificationConf `yaml:"memberInvited"` - MemberEnter NotificationConf `yaml:"memberEnter"` - GroupDismissed NotificationConf `yaml:"groupDismissed"` - GroupMuted NotificationConf `yaml:"groupMuted"` - GroupCancelMuted NotificationConf `yaml:"groupCancelMuted"` - GroupMemberMuted NotificationConf `yaml:"groupMemberMuted"` - GroupMemberCancelMuted NotificationConf `yaml:"groupMemberCancelMuted"` - GroupMemberInfoSet NotificationConf `yaml:"groupMemberInfoSet"` - GroupMemberSetToAdmin NotificationConf `yaml:"groupMemberSetToAdmin"` - GroupMemberSetToOrdinary NotificationConf `yaml:"groupMemberSetToOrdinaryUser"` - GroupInfoSetAnnouncement NotificationConf `yaml:"groupInfoSetAnnouncement"` - GroupInfoSetName NotificationConf `yaml:"groupInfoSetName"` - ////////////////////////user/////////////////////// - UserInfoUpdated NotificationConf `yaml:"userInfoUpdated"` - //////////////////////friend/////////////////////// - FriendApplicationAdded NotificationConf `yaml:"friendApplicationAdded"` - FriendApplicationApproved NotificationConf `yaml:"friendApplicationApproved"` - FriendApplicationRejected NotificationConf `yaml:"friendApplicationRejected"` - FriendAdded NotificationConf `yaml:"friendAdded"` - FriendDeleted NotificationConf `yaml:"friendDeleted"` - FriendRemarkSet NotificationConf `yaml:"friendRemarkSet"` - BlackAdded NotificationConf `yaml:"blackAdded"` - BlackDeleted NotificationConf `yaml:"blackDeleted"` - FriendInfoUpdated NotificationConf `yaml:"friendInfoUpdated"` - //////////////////////conversation/////////////////////// - ConversationChanged NotificationConf `yaml:"conversationChanged"` - ConversationSetPrivate NotificationConf `yaml:"conversationSetPrivate"` -} - -func GetServiceNames() []string { - return []string{ - Config.RpcRegisterName.OpenImUserName, - Config.RpcRegisterName.OpenImFriendName, - Config.RpcRegisterName.OpenImMsgName, - Config.RpcRegisterName.OpenImPushName, - Config.RpcRegisterName.OpenImMessageGatewayName, - Config.RpcRegisterName.OpenImGroupName, - Config.RpcRegisterName.OpenImAuthName, - Config.RpcRegisterName.OpenImConversationName, - Config.RpcRegisterName.OpenImThirdName, - } -} diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index 3e15fe57a..f31df39d2 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -15,8 +15,9 @@ package config import ( - "bytes" + _ "embed" "fmt" + "github.com/OpenIMSDK/tools/config" "os" "path/filepath" "runtime" @@ -24,10 +25,16 @@ import ( "gopkg.in/yaml.v3" "github.com/OpenIMSDK/tools/constant" - "github.com/OpenIMSDK/tools/discoveryregistry" "github.com/OpenIMSDK/tools/utils" ) +//go:embed version +var version string + +func init() { + config.Version = version +} + var ( _, b, _, _ = runtime.Caller(0) // Root folder of this project. @@ -37,12 +44,10 @@ var ( const ( FileName = "config.yaml" NotificationFileName = "notification.yaml" - ENV = "CONFIG_NAME" DefaultFolderPath = "../config/" - ConfKey = "conf" ) -func GetOptionsByNotification(cfg NotificationConf) utils.Options { +func GetOptionsByNotification(cfg config.NotificationConf) utils.Options { opts := utils.NewOptions() if cfg.UnreadCount { opts = utils.WithOptions(opts, utils.WithUnreadCount(true)) @@ -59,18 +64,7 @@ func GetOptionsByNotification(cfg NotificationConf) utils.Options { return opts } -func (c *config) unmarshalConfig(config interface{}, configPath string) error { - bytes, err := os.ReadFile(configPath) - if err != nil { - return err - } - if err = yaml.Unmarshal(bytes, config); err != nil { - return err - } - return nil -} - -func (c *config) initConfig(config interface{}, configName, configFolderPath string) error { +func initConfig(config interface{}, configName, configFolderPath string) error { if configFolderPath == "" { configFolderPath = DefaultFolderPath } @@ -87,37 +81,24 @@ func (c *config) initConfig(config interface{}, configName, configFolderPath str } else { Root = filepath.Dir(configPath) } - return c.unmarshalConfig(config, configPath) -} - -func (c *config) RegisterConf2Registry(registry discoveryregistry.SvcDiscoveryRegistry) error { - bytes, err := yaml.Marshal(Config) + data, err := os.ReadFile(configPath) if err != nil { return err } - return registry.RegisterConf2Registry(ConfKey, bytes) -} - -func (c *config) GetConfFromRegistry(registry discoveryregistry.SvcDiscoveryRegistry) ([]byte, error) { - return registry.GetConfFromRegistry(ConfKey) + if err = yaml.Unmarshal(data, config); err != nil { + return err + } + return nil } func InitConfig(configFolderPath string) error { - err := Config.initConfig(&Config, FileName, configFolderPath) + err := initConfig(&config.Config, FileName, configFolderPath) if err != nil { return err } - err = Config.initConfig(&Config.Notification, NotificationFileName, configFolderPath) + err = initConfig(&config.Config.Notification, NotificationFileName, configFolderPath) if err != nil { return err } return nil } - -func EncodeConfig() []byte { - buf := bytes.NewBuffer(nil) - if err := yaml.NewEncoder(buf).Encode(Config); err != nil { - panic(err) - } - return buf.Bytes() -} diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go deleted file mode 100644 index 3f34b9734..000000000 --- a/pkg/common/constant/constant.go +++ /dev/null @@ -1,363 +0,0 @@ -// Copyright © 2023 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package constant - -const ( - - ///ContentType - //UserRelated. - ContentTypeBegin = 100 - Text = 101 - Picture = 102 - Voice = 103 - Video = 104 - File = 105 - AtText = 106 - Merger = 107 - Card = 108 - Location = 109 - Custom = 110 - Revoke = 111 - Typing = 113 - Quote = 114 - - AdvancedText = 117 - - CustomNotTriggerConversation = 119 - CustomOnlineOnly = 120 - ReactionMessageModifier = 121 - ReactionMessageDeleter = 122 - - Common = 200 - GroupMsg = 201 - SignalMsg = 202 - CustomNotification = 203 - - // SysRelated. - NotificationBegin = 1000 - - FriendApplicationApprovedNotification = 1201 // add_friend_response - FriendApplicationRejectedNotification = 1202 // add_friend_response - FriendApplicationNotification = 1203 // add_friend - FriendAddedNotification = 1204 - FriendDeletedNotification = 1205 // delete_friend - FriendRemarkSetNotification = 1206 // set_friend_remark? - BlackAddedNotification = 1207 // add_black - BlackDeletedNotification = 1208 // remove_black - FriendInfoUpdatedNotification = 1209 - - ConversationChangeNotification = 1300 // change conversation opt - - UserNotificationBegin = 1301 - UserInfoUpdatedNotification = 1303 // SetSelfInfoTip = 204 - UserNotificationEnd = 1399 - OANotification = 1400 - - GroupNotificationBegin = 1500 - - GroupCreatedNotification = 1501 - GroupInfoSetNotification = 1502 - JoinGroupApplicationNotification = 1503 - MemberQuitNotification = 1504 - GroupApplicationAcceptedNotification = 1505 - GroupApplicationRejectedNotification = 1506 - GroupOwnerTransferredNotification = 1507 - MemberKickedNotification = 1508 - MemberInvitedNotification = 1509 - MemberEnterNotification = 1510 - GroupDismissedNotification = 1511 - GroupMemberMutedNotification = 1512 - GroupMemberCancelMutedNotification = 1513 - GroupMutedNotification = 1514 - GroupCancelMutedNotification = 1515 - GroupMemberInfoSetNotification = 1516 - GroupMemberSetToAdminNotification = 1517 - GroupMemberSetToOrdinaryUserNotification = 1518 - GroupInfoSetAnnouncementNotification = 1519 - GroupInfoSetNameNotification = 1520 - - SignalingNotificationBegin = 1600 - SignalingNotification = 1601 - SignalingNotificationEnd = 1649 - - SuperGroupNotificationBegin = 1650 - SuperGroupUpdateNotification = 1651 - MsgDeleteNotification = 1652 - SuperGroupNotificationEnd = 1699 - - ConversationPrivateChatNotification = 1701 - ConversationUnreadNotification = 1702 - - MsgRevokeNotification = 2101 - - BusinessNotificationBegin = 2000 - BusinessNotification = 2001 - BusinessNotificationEnd = 2099 - - ClearConversationNotification = 2101 - DeleteMsgsNotification = 2102 - - HasReadReceipt = 2200 - - NotificationEnd = 5000 - - // status. - MsgNormal = 1 - MsgDeleted = 4 - - // MsgFrom. - UserMsgType = 100 - SysMsgType = 200 - - // SessionType. - SingleChatType = 1 - GroupChatType = 2 - SuperGroupChatType = 3 - NotificationChatType = 4 - // token. - NormalToken = 0 - InValidToken = 1 - KickedToken = 2 - ExpiredToken = 3 - - // MultiTerminalLogin. - DefalutNotKick = 0 - // Full-end login, but the same end is mutually exclusive. - AllLoginButSameTermKick = 1 - // Only one of the endpoints can log in. - SingleTerminalLogin = 2 - // The web side can be online at the same time, and the other side can only log in at one end. - WebAndOther = 3 - // The PC side is mutually exclusive, and the mobile side is mutually exclusive, but the web side can be online at - // the same time. - PcMobileAndWeb = 4 - // The PC terminal can be online at the same time,but other terminal only one of the endpoints can login. - PCAndOther = 5 - - OnlineStatus = "online" - OfflineStatus = "offline" - Registered = "registered" - UnRegistered = "unregistered" - - // MsgReceiveOpt. - ReceiveMessage = 0 - NotReceiveMessage = 1 - ReceiveNotNotifyMessage = 2 - - // OptionsKey. - IsHistory = "history" - IsPersistent = "persistent" - IsOfflinePush = "offlinePush" - IsUnreadCount = "unreadCount" - IsConversationUpdate = "conversationUpdate" - IsSenderSync = "senderSync" - IsNotPrivate = "notPrivate" - IsSenderConversationUpdate = "senderConversationUpdate" - IsSenderNotificationPush = "senderNotificationPush" - IsReactionFromCache = "reactionFromCache" - IsNotNotification = "isNotNotification" - IsSendMsg = "isSendMsg" - - // GroupStatus. - GroupOk = 0 - GroupBanChat = 1 - GroupStatusDismissed = 2 - GroupStatusMuted = 3 - - // GroupType. - NormalGroup = 0 - SuperGroup = 1 - WorkingGroup = 2 - - GroupBaned = 3 - GroupBanPrivateChat = 4 - - // UserJoinGroupSource. - JoinByAdmin = 1 - - JoinByInvitation = 2 - JoinBySearch = 3 - JoinByQRCode = 4 - - // Minio. - MinioDurationTimes = 3600 - // Aws. - AwsDurationTimes = 3600 - - // callbackCommand. - CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsgCommand" - CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsgCommand" - CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsgCommand" - CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand" - CallbackMsgModifyCommand = "callbackMsgModifyCommand" - CallbackUserOnlineCommand = "callbackUserOnlineCommand" - CallbackUserOfflineCommand = "callbackUserOfflineCommand" - CallbackUserKickOffCommand = "callbackUserKickOffCommand" - CallbackOfflinePushCommand = "callbackOfflinePushCommand" - CallbackOnlinePushCommand = "callbackOnlinePushCommand" - CallbackSuperGroupOnlinePushCommand = "callbackSuperGroupOnlinePushCommand" - CallbackBeforeAddFriendCommand = "callbackBeforeAddFriendCommand" - CallbackBeforeCreateGroupCommand = "callbackBeforeCreateGroupCommand" - CallbackBeforeMemberJoinGroupCommand = "callbackBeforeMemberJoinGroupCommand" - CallbackBeforeSetGroupMemberInfoCommand = "CallbackBeforeSetGroupMemberInfoCommand" - CallbackBeforeSetMessageReactionExtensionCommand = "callbackBeforeSetMessageReactionExtensionCommand" - CallbackBeforeDeleteMessageReactionExtensionsCommand = "callbackBeforeDeleteMessageReactionExtensionsCommand" - CallbackGetMessageListReactionExtensionsCommand = "callbackGetMessageListReactionExtensionsCommand" - CallbackAddMessageListReactionExtensionsCommand = "callbackAddMessageListReactionExtensionsCommand" - - // callback actionCode. - ActionAllow = 0 - ActionForbidden = 1 - // callback callbackHandleCode. - CallbackHandleSuccess = 0 - CallbackHandleFailed = 1 - - // minioUpload. - OtherType = 1 - VideoType = 2 - ImageType = 3 - - // sendMsgStaus. - MsgStatusNotExist = 0 - MsgIsSending = 1 - MsgSendSuccessed = 2 - MsgSendFailed = 3 -) - -const ( - WriteDiffusion = 0 - ReadDiffusion = 1 -) - -const ( - UnreliableNotification = 1 - ReliableNotificationNoMsg = 2 - ReliableNotificationMsg = 3 -) - -const ( - AtAllString = "AtAllTag" - AtNormal = 0 - AtMe = 1 - AtAll = 2 - AtAllAtMe = 3 - GroupNotification = 4 -) - -var ContentType2PushContent = map[int64]string{ - Picture: "[PICTURE]", - Voice: "[VOICE]", - Video: "[VIDEO]", - File: "[File]", - Text: "[TEXT]", - AtText: "[@TEXT]", - GroupMsg: "[GROUPMSG]]", - Common: "[NEWMSG]", - SignalMsg: "[SIGNALINVITE]", -} - -const ( - FieldRecvMsgOpt = 1 - FieldIsPinned = 2 - FieldAttachedInfo = 3 - FieldIsPrivateChat = 4 - FieldGroupAtType = 5 - FieldEx = 7 - FieldUnread = 8 - FieldBurnDuration = 9 - FieldHasReadSeq = 10 -) - -const ( - AppOrdinaryUsers = 1 - AppAdmin = 2 - - GroupOwner = 100 - GroupAdmin = 60 - GroupOrdinaryUsers = 20 - - GroupResponseAgree = 1 - GroupResponseRefuse = -1 - - FriendResponseNotHandle = 0 - FriendResponseAgree = 1 - FriendResponseRefuse = -1 - - Male = 1 - Female = 2 -) - -const ( - OperationID = "operationID" - OpUserID = "opUserID" - ConnID = "connID" - OpUserPlatform = "platform" - Token = "token" - RpcCustomHeader = "customHeader" // rpc中间件自定义ctx参数 - CheckKey = "CheckKey" - TriggerID = "triggerID" - RemoteAddr = "remoteAddr" -) - -const ( - BecomeFriendByImport = 1 // 管理员导入 - BecomeFriendByApply = 2 // 申请添加 -) - -const ( - ApplyNeedVerificationInviteDirectly = 0 // 申请需要同意 邀请直接进 - AllNeedVerification = 1 // 所有人进群需要验证,除了群主管理员邀请进群 - Directly = 2 // 直接进群 -) - -const ( - GroupRPCRecvSize = 30 - GroupRPCSendSize = 30 -) - -const FriendAcceptTip = "You have successfully become friends, so start chatting" - -func GroupIsBanChat(status int32) bool { - if status != GroupStatusMuted { - return false - } - return true -} - -func GroupIsBanPrivateChat(status int32) bool { - if status != GroupBanPrivateChat { - return false - } - return true -} - -const LogFileName = "OpenIM.log" - -const LocalHost = "0.0.0.0" - -// flag parse. -const ( - FlagPort = "port" - FlagWsPort = "ws_port" - - FlagPrometheusPort = "prometheus_port" - FlagConf = "config_folder_path" -) - -const OpenIMCommonConfigKey = "OpenIMServerConfig" - -const CallbackCommand = "command" - -const BatchNum = 100 diff --git a/pkg/common/constant/limit.go b/pkg/common/constant/limit.go deleted file mode 100644 index fd1551b34..000000000 --- a/pkg/common/constant/limit.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright © 2023 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package constant - -const ( - ShowNumber = 1000 - StatisticsTimeInterval = 60 - MaxNotificationNum = 500 -) diff --git a/pkg/common/constant/platform_id_to_name.go b/pkg/common/constant/platform_id_to_name.go deleted file mode 100644 index 3bc819ed9..000000000 --- a/pkg/common/constant/platform_id_to_name.go +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright © 2023 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package constant - -// fixme 1<--->IOS 2<--->Android 3<--->Windows -// fixme 4<--->OSX 5<--->Web 6<--->MiniWeb 7<--->Linux. -const ( - // Platform ID. - IOSPlatformID = 1 - AndroidPlatformID = 2 - WindowsPlatformID = 3 - OSXPlatformID = 4 - WebPlatformID = 5 - MiniWebPlatformID = 6 - LinuxPlatformID = 7 - AndroidPadPlatformID = 8 - IPadPlatformID = 9 - AdminPlatformID = 10 - - // Platform string match to Platform ID. - IOSPlatformStr = "IOS" - AndroidPlatformStr = "Android" - WindowsPlatformStr = "Windows" - OSXPlatformStr = "OSX" - WebPlatformStr = "Web" - MiniWebPlatformStr = "MiniWeb" - LinuxPlatformStr = "Linux" - AndroidPadPlatformStr = "APad" - IPadPlatformStr = "IPad" - AdminPlatformStr = "Admin" - - // terminal types. - TerminalPC = "PC" - TerminalMobile = "Mobile" -) - -var PlatformID2Name = map[int]string{ - IOSPlatformID: IOSPlatformStr, - AndroidPlatformID: AndroidPlatformStr, - WindowsPlatformID: WindowsPlatformStr, - OSXPlatformID: OSXPlatformStr, - WebPlatformID: WebPlatformStr, - MiniWebPlatformID: MiniWebPlatformStr, - LinuxPlatformID: LinuxPlatformStr, - AndroidPadPlatformID: AndroidPadPlatformStr, - IPadPlatformID: IPadPlatformStr, - AdminPlatformID: AdminPlatformStr, -} - -var PlatformName2ID = map[string]int{ - IOSPlatformStr: IOSPlatformID, - AndroidPlatformStr: AndroidPlatformID, - WindowsPlatformStr: WindowsPlatformID, - OSXPlatformStr: OSXPlatformID, - WebPlatformStr: WebPlatformID, - MiniWebPlatformStr: MiniWebPlatformID, - LinuxPlatformStr: LinuxPlatformID, - AndroidPadPlatformStr: AndroidPadPlatformID, - IPadPlatformStr: IPadPlatformID, - AdminPlatformStr: AdminPlatformID, -} - -var PlatformName2class = map[string]string{ - IOSPlatformStr: TerminalMobile, - AndroidPlatformStr: TerminalMobile, - MiniWebPlatformStr: WebPlatformStr, - WebPlatformStr: WebPlatformStr, - WindowsPlatformStr: TerminalPC, - OSXPlatformStr: TerminalPC, - LinuxPlatformStr: TerminalPC, -} - -var PlatformID2class = map[int]string{ - IOSPlatformID: TerminalMobile, - AndroidPlatformID: TerminalMobile, - MiniWebPlatformID: WebPlatformStr, - WebPlatformID: WebPlatformStr, - WindowsPlatformID: TerminalPC, - OSXPlatformID: TerminalPC, - LinuxPlatformID: TerminalPC, -} - -func PlatformIDToName(num int) string { - return PlatformID2Name[num] -} - -func PlatformNameToID(name string) int { - return PlatformName2ID[name] -} - -func PlatformNameToClass(name string) string { - return PlatformName2class[name] -} - -func PlatformIDToClass(num int) string { - return PlatformID2class[num] -}