You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
2 years ago
|
package getcdv3
|
||
2 years ago
|
|
||
|
import (
|
||
|
"Open_IM/pkg/common/config"
|
||
2 years ago
|
"Open_IM/pkg/utils"
|
||
2 years ago
|
"context"
|
||
2 years ago
|
"fmt"
|
||
2 years ago
|
"github.com/OpenIMSDK/getcdv3"
|
||
2 years ago
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||
|
"time"
|
||
2 years ago
|
|
||
2 years ago
|
"gopkg.in/yaml.v3"
|
||
2 years ago
|
"strings"
|
||
|
)
|
||
|
|
||
2 years ago
|
func registerConf(key, conf string) {
|
||
|
etcdAddr := strings.Join(config.Config.Etcd.EtcdAddr, ",")
|
||
|
cli, err := clientv3.New(clientv3.Config{
|
||
|
Endpoints: strings.Split(etcdAddr, ","), DialTimeout: 5 * time.Second})
|
||
|
|
||
|
if err != nil {
|
||
|
panic(err.Error())
|
||
|
}
|
||
|
//lease
|
||
|
if _, err := cli.Put(context.Background(), key, conf); err != nil {
|
||
|
fmt.Println("panic, params: ")
|
||
|
panic(err.Error())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func RegisterConf() {
|
||
|
bytes, err := yaml.Marshal(config.Config)
|
||
|
if err != nil {
|
||
|
panic(err.Error())
|
||
|
}
|
||
2 years ago
|
secretMD5 := utils.Md5(config.Config.Etcd.Secret)
|
||
|
confBytes, err := utils.AesEncrypt(bytes, []byte(secretMD5[0:16]))
|
||
2 years ago
|
if err != nil {
|
||
|
panic(err.Error())
|
||
|
}
|
||
|
fmt.Println("start register", secretMD5, getcdv3.GetPrefix(config.Config.Etcd.EtcdSchema, config.ConfName))
|
||
|
registerConf(getcdv3.GetPrefix(config.Config.Etcd.EtcdSchema, config.ConfName), string(confBytes))
|
||
|
fmt.Println("etcd register conf ok")
|
||
|
}
|