From dd14dba36d190bd7b3bd308d71f9285c425d6660 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw)" <3293172751nss@gmail.com> Date: Mon, 23 Oct 2023 08:55:52 +0800 Subject: [PATCH] docs: add openim flag Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> --- cmd/api/chat-api/main.go | 6 +++--- internal/rpc/admin/ip_forbidden.go | 2 +- internal/rpc/admin/register_add_group.go | 2 +- internal/rpc/admin/user.go | 4 ++-- internal/rpc/admin/user_ip_limit_login.go | 2 +- pkg/common/chatrpcstart/start.go | 10 +++++----- pkg/common/config/parse.go | 5 +++-- pkg/common/db/model/admin/admin.go | 2 +- pkg/common/db/model/chat/user_login_record.go | 2 +- .../k8s_discovery_register.go | 20 ++++++++++--------- pkg/sms/sms.go | 2 +- 11 files changed, 30 insertions(+), 27 deletions(-) diff --git a/cmd/api/chat-api/main.go b/cmd/api/chat-api/main.go index 865fb77fb..187b60de2 100644 --- a/cmd/api/chat-api/main.go +++ b/cmd/api/chat-api/main.go @@ -17,14 +17,14 @@ package main import ( "flag" "fmt" - "github.com/OpenIMSDK/chat/pkg/discovery_register" - "github.com/OpenIMSDK/chat/tools/component" - "github.com/OpenIMSDK/tools/discoveryregistry" "math/rand" "net" "strconv" "time" + "github.com/OpenIMSDK/chat/pkg/discovery_register" + "github.com/OpenIMSDK/tools/discoveryregistry" + "github.com/OpenIMSDK/chat/tools/component" mw2 "github.com/OpenIMSDK/chat/pkg/common/mw" diff --git a/internal/rpc/admin/ip_forbidden.go b/internal/rpc/admin/ip_forbidden.go index b663f458c..6f5f3b7c0 100644 --- a/internal/rpc/admin/ip_forbidden.go +++ b/internal/rpc/admin/ip_forbidden.go @@ -16,8 +16,8 @@ package admin import ( "context" - "time" "github.com/OpenIMSDK/tools/log" + "time" admin2 "github.com/OpenIMSDK/chat/pkg/common/db/table/admin" "github.com/OpenIMSDK/chat/pkg/common/mctx" diff --git a/internal/rpc/admin/register_add_group.go b/internal/rpc/admin/register_add_group.go index 1c724b0e9..32dc3c542 100644 --- a/internal/rpc/admin/register_add_group.go +++ b/internal/rpc/admin/register_add_group.go @@ -19,8 +19,8 @@ import ( "strings" "time" - "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/errs" + "github.com/OpenIMSDK/tools/log" "github.com/OpenIMSDK/tools/utils" admin2 "github.com/OpenIMSDK/chat/pkg/common/db/table/admin" diff --git a/internal/rpc/admin/user.go b/internal/rpc/admin/user.go index a83339f51..b5dbfd6f4 100644 --- a/internal/rpc/admin/user.go +++ b/internal/rpc/admin/user.go @@ -16,10 +16,10 @@ package admin import ( "context" - "strings" - "time" "github.com/OpenIMSDK/chat/pkg/common/constant" "github.com/OpenIMSDK/tools/log" + "strings" + "time" "github.com/OpenIMSDK/protocol/wrapperspb" "github.com/OpenIMSDK/tools/errs" diff --git a/internal/rpc/admin/user_ip_limit_login.go b/internal/rpc/admin/user_ip_limit_login.go index b40bfdd4b..a93fbf789 100644 --- a/internal/rpc/admin/user_ip_limit_login.go +++ b/internal/rpc/admin/user_ip_limit_login.go @@ -16,8 +16,8 @@ package admin import ( "context" - "time" "github.com/OpenIMSDK/tools/log" + "time" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/utils" diff --git a/pkg/common/chatrpcstart/start.go b/pkg/common/chatrpcstart/start.go index 8be72f576..446447f82 100644 --- a/pkg/common/chatrpcstart/start.go +++ b/pkg/common/chatrpcstart/start.go @@ -16,6 +16,9 @@ package chatrpcstart import ( "fmt" + "net" + "strconv" + "github.com/OpenIMSDK/chat/pkg/common/config" chatMw "github.com/OpenIMSDK/chat/pkg/common/mw" "github.com/OpenIMSDK/chat/pkg/discovery_register" @@ -26,8 +29,6 @@ import ( "github.com/OpenIMSDK/tools/utils" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "net" - "strconv" ) func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error, options ...grpc.ServerOption) error { @@ -38,11 +39,10 @@ func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(c /* zkClient, err := openKeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema, openKeeper.WithFreq(time.Hour), openKeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username, - config.Config.Zookeeper.Password), openKeeper.WithRoundRobin(), openKeeper.WithTimeout(10), openKeeper.WithLogger(log.NewZkLogger()))*/ - if err != nil { + config.Config.Zookeeper.Password), openKeeper.WithRoundRobin(), openKeeper.WithTimeout(10), openKeeper.WithLogger(log.NewZkLogger()))*/if err != nil { return errs.Wrap(err) } - //defer zkClient.CloseZK() + // defer zkClient.CloseZK() zkClient.AddOption(chatMw.AddUserType(), mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) registerIP, err := network.GetRpcRegisterIP(config.Config.Rpc.RegisterIP) if err != nil { diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index 1edae7b94..280d9cc4f 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -18,13 +18,14 @@ import ( "bytes" "errors" "fmt" - "github.com/OpenIMSDK/protocol/constant" - openKeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper" "os" "path/filepath" "runtime" "time" + "github.com/OpenIMSDK/protocol/constant" + openKeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper" + "github.com/OpenIMSDK/tools/utils" "gopkg.in/yaml.v3" ) diff --git a/pkg/common/db/model/admin/admin.go b/pkg/common/db/model/admin/admin.go index e5447b653..f4e8d04a6 100644 --- a/pkg/common/db/model/admin/admin.go +++ b/pkg/common/db/model/admin/admin.go @@ -18,8 +18,8 @@ import ( "context" "crypto/md5" "encoding/hex" - "time" "github.com/OpenIMSDK/tools/log" + "time" "github.com/OpenIMSDK/chat/pkg/common/config" "github.com/OpenIMSDK/chat/pkg/common/db/table/admin" diff --git a/pkg/common/db/model/chat/user_login_record.go b/pkg/common/db/model/chat/user_login_record.go index 85f234fc0..24c5b5169 100644 --- a/pkg/common/db/model/chat/user_login_record.go +++ b/pkg/common/db/model/chat/user_login_record.go @@ -16,8 +16,8 @@ package chat import ( "context" - "time" "github.com/OpenIMSDK/tools/errs" + "time" "gorm.io/gorm" diff --git a/pkg/discovery_register/k8s_discovery_register.go b/pkg/discovery_register/k8s_discovery_register.go index 26173032e..b24859ed7 100644 --- a/pkg/discovery_register/k8s_discovery_register.go +++ b/pkg/discovery_register/k8s_discovery_register.go @@ -4,12 +4,13 @@ import ( "context" "errors" "fmt" + "time" + "github.com/OpenIMSDK/chat/pkg/common/config" "github.com/OpenIMSDK/tools/discoveryregistry" openkeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper" "github.com/OpenIMSDK/tools/log" "google.golang.org/grpc" - "time" ) func NewDiscoveryRegister(envType string) (discoveryregistry.SvcDiscoveryRegistry, error) { @@ -44,44 +45,45 @@ func (cli *K8sDR) Register(serviceName, host string, port int, opts ...grpc.Dial cli.rpcRegisterAddr = serviceName return nil } -func (cli *K8sDR) UnRegister() error { +func (cli *K8sDR) UnRegister() error { return nil } -func (cli *K8sDR) CreateRpcRootNodes(serviceNames []string) error { +func (cli *K8sDR) CreateRpcRootNodes(serviceNames []string) error { return nil } -func (cli *K8sDR) RegisterConf2Registry(key string, conf []byte) error { +func (cli *K8sDR) RegisterConf2Registry(key string, conf []byte) error { return nil } func (cli *K8sDR) GetConfFromRegistry(key string) ([]byte, error) { - 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...)...) 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...)...) } -func (cli *K8sDR) GetSelfConnTarget() string { +func (cli *K8sDR) GetSelfConnTarget() string { return cli.rpcRegisterAddr } + func (cli *K8sDR) AddOption(opts ...grpc.DialOption) { cli.options = append(cli.options, opts...) } + func (cli *K8sDR) CloseConn(conn *grpc.ClientConn) { 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 { fmt.Println("should not call this function!!!!!!!!!!!!!!!!!!!!!!!!!") return nil diff --git a/pkg/sms/sms.go b/pkg/sms/sms.go index 05e468c78..ba3a91429 100644 --- a/pkg/sms/sms.go +++ b/pkg/sms/sms.go @@ -17,8 +17,8 @@ package sms import ( "context" "fmt" - "strings" "github.com/OpenIMSDK/chat/pkg/common/config" + "strings" ) func New() (SMS, error) {