mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-07 10:35:59 +08:00
Merge branch 'main' into localcache
# Conflicts: # go.mod # go.sum # internal/msggateway/hub_server.go # internal/push/consumer_init.go # internal/push/offlinepush/fcm/push.go # internal/push/offlinepush/getui/push.go # internal/push/offlinepush/jpush/push.go # internal/push/push_handler.go # internal/push/push_rpc_server.go # internal/push/push_to_client.go # internal/rpc/friend/friend.go # internal/rpc/msg/server.go # internal/rpc/msg/verify.go # pkg/common/config/config.go # pkg/common/db/cache/conversation.go # pkg/common/db/cache/meta_cache.go # pkg/common/db/cache/msg.go # pkg/common/db/localcache/conversation.go # pkg/common/db/localcache/group.go # pkg/rpcclient/conversation.go # pkg/rpcclient/group.go
This commit is contained in:
@@ -22,7 +22,7 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var Config configStruct
|
||||
var Config GlobalConfig
|
||||
|
||||
const ConfKey = "conf"
|
||||
|
||||
@@ -58,7 +58,7 @@ type MYSQL struct {
|
||||
SlowThreshold int `yaml:"slowThreshold"`
|
||||
}
|
||||
|
||||
type configStruct struct {
|
||||
type GlobalConfig struct {
|
||||
Envs struct {
|
||||
Discovery string `yaml:"discovery"`
|
||||
}
|
||||
@@ -165,6 +165,14 @@ type configStruct struct {
|
||||
SessionToken string `yaml:"sessionToken"`
|
||||
PublicRead bool `yaml:"publicRead"`
|
||||
} `yaml:"kodo"`
|
||||
Aws struct {
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
Region string `yaml:"region"`
|
||||
Bucket string `yaml:"bucket"`
|
||||
AccessKeyID string `yaml:"accessKeyID"`
|
||||
AccessKeySecret string `yaml:"accessKeySecret"`
|
||||
PublicRead bool `yaml:"publicRead"`
|
||||
} `yaml:"aws"`
|
||||
} `yaml:"object"`
|
||||
|
||||
RpcPort struct {
|
||||
@@ -334,6 +342,10 @@ type configStruct struct {
|
||||
Notification notification `yaml:"notification"`
|
||||
}
|
||||
|
||||
func NewGlobalConfig() *GlobalConfig {
|
||||
return &GlobalConfig{}
|
||||
}
|
||||
|
||||
type notification struct {
|
||||
GroupCreated NotificationConf `yaml:"groupCreated"`
|
||||
GroupInfoSet NotificationConf `yaml:"groupInfoSet"`
|
||||
@@ -400,7 +412,7 @@ type localCache struct {
|
||||
Conversation LocalCache `yaml:"conversation"`
|
||||
}
|
||||
|
||||
func (c *configStruct) GetServiceNames() []string {
|
||||
func (c *GlobalConfig) GetServiceNames() []string {
|
||||
return []string{
|
||||
c.RpcRegisterName.OpenImUserName,
|
||||
c.RpcRegisterName.OpenImFriendName,
|
||||
@@ -414,7 +426,7 @@ func (c *configStruct) GetServiceNames() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configStruct) RegisterConf2Registry(registry discoveryregistry.SvcDiscoveryRegistry) error {
|
||||
func (c *GlobalConfig) RegisterConf2Registry(registry discoveryregistry.SvcDiscoveryRegistry) error {
|
||||
data, err := yaml.Marshal(c)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -422,11 +434,11 @@ func (c *configStruct) RegisterConf2Registry(registry discoveryregistry.SvcDisco
|
||||
return registry.RegisterConf2Registry(ConfKey, data)
|
||||
}
|
||||
|
||||
func (c *configStruct) GetConfFromRegistry(registry discoveryregistry.SvcDiscoveryRegistry) ([]byte, error) {
|
||||
func (c *GlobalConfig) GetConfFromRegistry(registry discoveryregistry.SvcDiscoveryRegistry) ([]byte, error) {
|
||||
return registry.GetConfFromRegistry(ConfKey)
|
||||
}
|
||||
|
||||
func (c *configStruct) EncodeConfig() []byte {
|
||||
func (c *GlobalConfig) EncodeConfig() []byte {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
if err := yaml.NewEncoder(buf).Encode(c); err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -83,6 +83,9 @@ func GetOptionsByNotification(cfg NotificationConf) msgprocessor.Options {
|
||||
return opts
|
||||
}
|
||||
|
||||
// initConfig loads configuration from a specified path into the provided config structure.
|
||||
// If the specified config file does not exist, it attempts to load from the project's default "config" directory.
|
||||
// It logs informative messages regarding the configuration path being used.
|
||||
func initConfig(config any, configName, configFolderPath string) error {
|
||||
configFolderPath = filepath.Join(configFolderPath, configName)
|
||||
_, err := os.Stat(configFolderPath)
|
||||
@@ -101,12 +104,12 @@ func initConfig(config any, configName, configFolderPath string) error {
|
||||
if err = yaml.Unmarshal(data, config); err != nil {
|
||||
return fmt.Errorf("unmarshal yaml error: %w", err)
|
||||
}
|
||||
fmt.Println("use config", configFolderPath)
|
||||
fmt.Println("The path of the configuration file to start the process:", configFolderPath)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func InitConfig(configFolderPath string) error {
|
||||
func InitConfig(config *GlobalConfig, configFolderPath string) error {
|
||||
if configFolderPath == "" {
|
||||
envConfigPath := os.Getenv("OPENIMCONFIG")
|
||||
if envConfigPath != "" {
|
||||
@@ -116,9 +119,9 @@ func InitConfig(configFolderPath string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := initConfig(&Config, FileName, configFolderPath); err != nil {
|
||||
if err := initConfig(config, FileName, configFolderPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return initConfig(&Config.Notification, NotificationFileName, configFolderPath)
|
||||
return initConfig(&config.Notification, NotificationFileName, configFolderPath)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestGetDefaultConfigPath(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetDefaultConfigPath(); got != tt.want {
|
||||
if got, _ := GetDefaultConfigPath(); got != tt.want {
|
||||
t.Errorf("GetDefaultConfigPath() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
@@ -49,7 +49,7 @@ func TestGetProjectRoot(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetProjectRoot(); got != tt.want {
|
||||
if got, _ := GetProjectRoot(); got != tt.want {
|
||||
t.Errorf("GetProjectRoot() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
@@ -105,13 +105,14 @@ func TestInitConfig(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
config *GlobalConfig
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := InitConfig(tt.args.configFolderPath); (err != nil) != tt.wantErr {
|
||||
if err := InitConfig(tt.config, tt.args.configFolderPath); (err != nil) != tt.wantErr {
|
||||
t.Errorf("InitConfig() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user