ydb-platform / ydb-go-sdk

Pure Go native and database/sql driver for YDB
https://ydb.tech
Apache License 2.0
138 stars 73 forks source link

dev: make PreferLocations function pure #1285

Closed pelageech closed 3 months ago

pelageech commented 3 months ago

balancers.PreferLocations should be pure function and not modify the slice.

func PreferLocations(balancer *balancerConfig.Config, locations ...string) *balancerConfig.Config {
    if len(locations) == 0 {
        panic("empty list of locations")
    }
    for i := range locations { // need to copy the slice
        locations[i] = strings.ToUpper(locations[i])
    }
    sort.Strings(locations)
    balancer.Filter = filterLocations(locations)

    return balancer
}