This commit is contained in:
wangchuxiao
2023-02-08 17:56:04 +08:00
parent 4a32e98e62
commit 2193d380ca
19 changed files with 401 additions and 555 deletions
@@ -15,8 +15,12 @@ import (
)
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, strategy func(slice []*grpc.ClientConn) int, opts ...grpc.DialOption) (*grpc.ClientConn, error)
//RegisterConf(conf []byte) error
//LoadConf() ([]byte, error)
}
func registerConf(key, conf string) {
+28
View File
@@ -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
}
+1
View File
@@ -0,0 +1 @@
package discoveryRegistry