internal/serviceconfig: Fix typo and improve docs. (#3802)
This commit is contained in:
Родитель
2983360ff4
Коммит
6aaac03d17
|
@ -30,8 +30,11 @@ import (
|
|||
|
||||
var logger = grpclog.Component("core")
|
||||
|
||||
// BalancerConfig is the balancer config part that service config's
|
||||
// loadBalancingConfig fields can be unmarshalled to. It's a json unmarshaller.
|
||||
// BalancerConfig wraps the name and config associated with one load balancing
|
||||
// policy. It corresponds to a single entry of the loadBalancingConfig field
|
||||
// from ServiceConfig.
|
||||
//
|
||||
// It implements the json.Unmarshaler interface.
|
||||
//
|
||||
// https://github.com/grpc/grpc-proto/blob/54713b1e8bc6ed2d4f25fb4dff527842150b91b2/grpc/service_config/service_config.proto#L247
|
||||
type BalancerConfig struct {
|
||||
|
@ -41,7 +44,15 @@ type BalancerConfig struct {
|
|||
|
||||
type intermediateBalancerConfig []map[string]json.RawMessage
|
||||
|
||||
// UnmarshalJSON implements json unmarshaller.
|
||||
// UnmarshalJSON implements the json.Unmarshaler interface.
|
||||
//
|
||||
// ServiceConfig contains a list of loadBalancingConfigs, each with a name and
|
||||
// config. This method iterates through that list in order, and stops at the
|
||||
// first policy that is supported.
|
||||
// - If the config for the first supported policy is invalid, the whole service
|
||||
// config is invalid.
|
||||
// - If the list doesn't contain any supported policy, the whole service config
|
||||
// is invalid.
|
||||
func (bc *BalancerConfig) UnmarshalJSON(b []byte) error {
|
||||
var ir intermediateBalancerConfig
|
||||
err := json.Unmarshal(b, &ir)
|
||||
|
@ -53,13 +64,16 @@ func (bc *BalancerConfig) UnmarshalJSON(b []byte) error {
|
|||
if len(lbcfg) != 1 {
|
||||
return fmt.Errorf("invalid loadBalancingConfig: entry %v does not contain exactly 1 policy/config pair: %q", i, lbcfg)
|
||||
}
|
||||
|
||||
var (
|
||||
name string
|
||||
jsonCfg json.RawMessage
|
||||
)
|
||||
// Get the key:value pair from the map.
|
||||
// Get the key:value pair from the map. We have already made sure that
|
||||
// the map contains a single entry.
|
||||
for name, jsonCfg = range lbcfg {
|
||||
}
|
||||
|
||||
builder := balancer.Get(name)
|
||||
if builder == nil {
|
||||
// If the balancer is not registered, move on to the next config.
|
||||
|
|
Загрузка…
Ссылка в новой задаче