optimization: change the configuration file from being read globally … (#1935)

* optimization: change the configuration file from being read globally to being read independently.

* optimization: change the configuration file from being read globally to being read independently.

* optimization: change the configuration file from being read globally to being read independently.

* optimization: config file changed to dependency injection.

* fix: replace global config with dependency injection

* fix: replace global config with dependency injection

* fix: import the enough param

* fix: import the enough param

* fix: import the enough param

* fix: fix the component check of path

* fix: fix the kafka of tls is nil problem

* fix: fix the TLS.CACrt is nil error

* fix: fix the valiable shadows problem

* fix: fix the comflect

* optimization: message remove options.

* fix: fix the param pass error

* fix: find error

* fix: find error

* fix: find eror

* fix: find error

* fix: find error

* fix: del the undifined func

* fix: find error

* fix: fix the error

* fix: pass config

* fix: find error

* fix: find error

* fix: find error

* fix: find error

* fix: find error

* fix: fix the config

* fix: fix the error

* fix: fix the config pass error

* fix: fix the eror

* fix: fix the error

* fix: fix the error

* fix: fix the error

* fix: find error

* fix: fix the error

* fix: fix the config

* fix: add return err

* fix: fix the err2

* fix: err

* fix: fix the func

* fix: del the chinese comment

* fix: fix the func

* fix: fix the gateway_test logic

* fix: s3

* test

* test

* fix: not found

---------

Co-authored-by: luhaoling <2198702716@qq.com>
Co-authored-by: withchao <993506633@qq.com>
This commit is contained in:
OpenIM-Gordon
2024-03-05 17:53:22 +08:00
committed by GitHub
parent efb8310531
commit 383758782e
114 changed files with 1743 additions and 1802 deletions
+31 -4
View File
@@ -15,8 +15,12 @@
package tools
import (
"flag"
"fmt"
"github.com/OpenIMSDK/tools/errs"
"gopkg.in/yaml.v3"
"math/rand"
"os"
"sync"
"testing"
"time"
@@ -61,7 +65,7 @@ func TestCronWrapFunc(t *testing.T) {
start := time.Now()
key := fmt.Sprintf("cron-%v", rand.Int31())
crontab := cron.New(cron.WithSeconds())
crontab.AddFunc("*/1 * * * * *", cronWrapFunc(rdb, key, cb))
crontab.AddFunc("*/1 * * * * *", cronWrapFunc(config.NewGlobalConfig(), rdb, key, cb))
crontab.Start()
<-done
@@ -71,7 +75,11 @@ func TestCronWrapFunc(t *testing.T) {
}
func TestCronWrapFuncWithNetlock(t *testing.T) {
config.Config.EnableCronLocker = true
conf, err := initCfg()
if err != nil {
panic(err)
}
conf.EnableCronLocker = true
rdb := redis.NewClient(&redis.Options{})
defer rdb.Close()
@@ -80,10 +88,10 @@ func TestCronWrapFuncWithNetlock(t *testing.T) {
crontab := cron.New(cron.WithSeconds())
key := fmt.Sprintf("cron-%v", rand.Int31())
crontab.AddFunc("*/1 * * * * *", cronWrapFunc(rdb, key, func() {
crontab.AddFunc("*/1 * * * * *", cronWrapFunc(conf, rdb, key, func() {
done <- "host1"
}))
crontab.AddFunc("*/1 * * * * *", cronWrapFunc(rdb, key, func() {
crontab.AddFunc("*/1 * * * * *", cronWrapFunc(conf, rdb, key, func() {
done <- "host2"
}))
crontab.Start()
@@ -94,3 +102,22 @@ func TestCronWrapFuncWithNetlock(t *testing.T) {
crontab.Stop()
}
func initCfg() (*config.GlobalConfig, error) {
const (
defaultCfgPath = "../../../../../config/config.yaml"
)
cfgPath := flag.String("c", defaultCfgPath, "Path to the configuration file")
data, err := os.ReadFile(*cfgPath)
if err != nil {
return nil, errs.Wrap(err, "ReadFile unmarshal failed")
}
conf := config.NewGlobalConfig()
err = yaml.Unmarshal(data, &conf)
if err != nil {
return nil, errs.Wrap(err, "InitConfig unmarshal failed")
}
return conf, nil
}