diff --git a/README.md b/README.md index 6e214cc..8a394c5 100644 --- a/README.md +++ b/README.md @@ -80,5 +80,5 @@ HTTP_GW_WEB_MAX_REQUEST_BODY_SIZE=4194304 - maximum request body size, server r Peers preset: HTTP_GW_PEERS__ADDRESS = string -HTTP_GW_PEERS__WEIGHT = 0..1 (float) +HTTP_GW_PEERS__WEIGHT = float ``` diff --git a/connections/pool.go b/connections/pool.go index 256acfa..f8b8f57 100644 --- a/connections/pool.go +++ b/connections/pool.go @@ -3,7 +3,6 @@ package connections import ( "context" "crypto/ecdsa" - "math" "math/rand" "sync" "time" @@ -40,8 +39,8 @@ func (pb *PoolBuilder) Build(ctx context.Context, options *PoolBuilderOptions) ( for _, w := range pb.weights { totalWeight += w } - if math.Abs(totalWeight-1.0) >= 1e-4 { - return nil, errors.New("total weight must be equal to unity") + for i, w := range pb.weights { + pb.weights[i] = w / totalWeight } var cons = make([]*grpc.ClientConn, len(pb.addresses)) for i, address := range pb.addresses { diff --git a/settings.go b/settings.go index 32326cd..4e4dabb 100644 --- a/settings.go +++ b/settings.go @@ -183,7 +183,7 @@ func settings() *viper.Viper { fmt.Println() fmt.Printf("%s_%s_[N]_ADDRESS = string\n", Prefix, strings.ToUpper(cfgPeers)) - fmt.Printf("%s_%s_[N]_WEIGHT = 0..1 (float)\n", Prefix, strings.ToUpper(cfgPeers)) + fmt.Printf("%s_%s_[N]_WEIGHT = float\n", Prefix, strings.ToUpper(cfgPeers)) os.Exit(0) case version != nil && *version: