@@ -3,31 +3,31 @@ package balancers
33import (
44 "strings"
55
6+ balancerConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/config"
67 "github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
7- routerconfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/router/config"
88)
99
1010// Deprecated: RoundRobin is RandomChoice now
11- func RoundRobin () * routerconfig .Config {
12- return & routerconfig .Config {}
11+ func RoundRobin () * balancerConfig .Config {
12+ return & balancerConfig .Config {}
1313}
1414
15- func RandomChoice () * routerconfig .Config {
16- return & routerconfig .Config {}
15+ func RandomChoice () * balancerConfig .Config {
16+ return & balancerConfig .Config {}
1717}
1818
19- func SingleConn () * routerconfig .Config {
20- return & routerconfig .Config {
19+ func SingleConn () * balancerConfig .Config {
20+ return & balancerConfig .Config {
2121 SingleConn : true ,
2222 }
2323}
2424
2525// PreferLocalDC creates balancer which use endpoints only in location such as initial endpoint location
2626// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
2727// PreferLocalDC balancer try to autodetect local DC from client side.
28- func PreferLocalDC (balancer * routerconfig .Config ) * routerconfig .Config {
29- balancer .IsPreferConn = func (routerInfo routerconfig .Info , c conn.Conn ) bool {
30- return c .Endpoint ().Location () == routerInfo .SelfLocation
28+ func PreferLocalDC (balancer * balancerConfig .Config ) * balancerConfig .Config {
29+ balancer .IsPreferConn = func (info balancerConfig .Info , c conn.Conn ) bool {
30+ return c .Endpoint ().Location () == info .SelfLocation
3131 }
3232 balancer .DetectlocalDC = true
3333 return balancer
@@ -36,22 +36,22 @@ func PreferLocalDC(balancer *routerconfig.Config) *routerconfig.Config {
3636// PreferLocalDCWithFallBack creates balancer which use endpoints only in location such as initial endpoint location
3737// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
3838// If filter returned zero endpoints from all discovery endpoints list - used all endpoint instead
39- func PreferLocalDCWithFallBack (balancer * routerconfig .Config ) * routerconfig .Config {
39+ func PreferLocalDCWithFallBack (balancer * balancerConfig .Config ) * balancerConfig .Config {
4040 balancer = PreferLocalDC (balancer )
4141 balancer .AllowFalback = true
4242 return balancer
4343}
4444
4545// PreferLocations creates balancer which use endpoints only in selected locations (such as "ABC", "DEF", etc.)
4646// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
47- func PreferLocations (balancer * routerconfig .Config , locations ... string ) * routerconfig .Config {
47+ func PreferLocations (balancer * balancerConfig .Config , locations ... string ) * balancerConfig .Config {
4848 if len (locations ) == 0 {
4949 panic ("empty list of locations" )
5050 }
5151 for i := range locations {
5252 locations [i ] = strings .ToUpper (locations [i ])
5353 }
54- balancer .IsPreferConn = func (_ routerconfig .Info , c conn.Conn ) bool {
54+ balancer .IsPreferConn = func (_ balancerConfig .Info , c conn.Conn ) bool {
5555 location := strings .ToUpper (c .Endpoint ().Location ())
5656 for _ , l := range locations {
5757 if location == l {
@@ -66,7 +66,7 @@ func PreferLocations(balancer *routerconfig.Config, locations ...string) *router
6666// PreferLocationsWithFallback creates balancer which use endpoints only in selected locations
6767// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
6868// If filter returned zero endpoints from all discovery endpoints list - used all endpoint instead
69- func PreferLocationsWithFallback (balancer * routerconfig .Config , locations ... string ) * routerconfig .Config {
69+ func PreferLocationsWithFallback (balancer * balancerConfig .Config , locations ... string ) * balancerConfig .Config {
7070 balancer = PreferLocations (balancer , locations ... )
7171 balancer .AllowFalback = true
7272 return balancer
@@ -84,8 +84,8 @@ type Endpoint interface {
8484
8585// Prefer creates balancer which use endpoints by filter
8686// Balancer "balancer" defines balancing algorithm between endpoints selected with filter
87- func Prefer (balancer * routerconfig .Config , filter func (endpoint Endpoint ) bool ) * routerconfig .Config {
88- balancer .IsPreferConn = func (_ routerconfig .Info , c conn.Conn ) bool {
87+ func Prefer (balancer * balancerConfig .Config , filter func (endpoint Endpoint ) bool ) * balancerConfig .Config {
88+ balancer .IsPreferConn = func (_ balancerConfig .Info , c conn.Conn ) bool {
8989 return filter (c .Endpoint ())
9090 }
9191 return balancer
@@ -94,13 +94,13 @@ func Prefer(balancer *routerconfig.Config, filter func(endpoint Endpoint) bool)
9494// PreferWithFallback creates balancer which use endpoints by filter
9595// Balancer "balancer" defines balancing algorithm between endpoints selected with filter
9696// If filter returned zero endpoints from all discovery endpoints list - used all endpoint instead
97- func PreferWithFallback (balancer * routerconfig .Config , filter func (endpoint Endpoint ) bool ) * routerconfig .Config {
97+ func PreferWithFallback (balancer * balancerConfig .Config , filter func (endpoint Endpoint ) bool ) * balancerConfig .Config {
9898 balancer = Prefer (balancer , filter )
9999 balancer .AllowFalback = true
100100 return balancer
101101}
102102
103103// Default balancer used by default
104- func Default () * routerconfig .Config {
104+ func Default () * balancerConfig .Config {
105105 return RandomChoice ()
106106}
0 commit comments