mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-07 10:35:59 +08:00
errcode
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package discoveryregistry
|
||||
|
||||
import (
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type SvcDiscoveryRegistry interface {
|
||||
Register(serviceName, host string, port int, opts ...grpc.DialOption) error
|
||||
UnRegister() error
|
||||
GetConns(serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error)
|
||||
GetConn(serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
|
||||
//RegisterConf(conf []byte) error
|
||||
//LoadConf() ([]byte, error)
|
||||
}
|
||||
|
||||
//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())
|
||||
// }
|
||||
// secretMD5 := utils.Md5(config.Config.Etcd.Secret)
|
||||
// confBytes, err := utils.AesEncrypt(bytes, []byte(secretMD5[0:16]))
|
||||
// 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")
|
||||
//}
|
||||
@@ -0,0 +1,28 @@
|
||||
package discoveryregistry
|
||||
|
||||
import "google.golang.org/grpc"
|
||||
|
||||
type Robin struct {
|
||||
next int
|
||||
}
|
||||
|
||||
func (r *Robin) Robin(slice []*grpc.ClientConn) int {
|
||||
index := r.next
|
||||
r.next += 1
|
||||
if r.next > len(slice)-1 {
|
||||
r.next = 0
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
type Hash struct {
|
||||
}
|
||||
|
||||
func (r *Hash) Hash(slice []*grpc.ClientConn) int {
|
||||
index := r.next
|
||||
r.next += 1
|
||||
if r.next > len(slice)-1 {
|
||||
r.next = 0
|
||||
}
|
||||
return index
|
||||
}
|
||||
Reference in New Issue
Block a user