mirror of https://github.com/grpc/grpc-go.git
internal/serviceconfig: Fix typo and improve docs. (#3802)
This commit is contained in:
parent
2983360ff4
commit
6aaac03d17
|
|
@ -30,8 +30,11 @@ import (
|
||||||
|
|
||||||
var logger = grpclog.Component("core")
|
var logger = grpclog.Component("core")
|
||||||
|
|
||||||
// BalancerConfig is the balancer config part that service config's
|
// BalancerConfig wraps the name and config associated with one load balancing
|
||||||
// loadBalancingConfig fields can be unmarshalled to. It's a json unmarshaller.
|
// 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
|
// https://github.com/grpc/grpc-proto/blob/54713b1e8bc6ed2d4f25fb4dff527842150b91b2/grpc/service_config/service_config.proto#L247
|
||||||
type BalancerConfig struct {
|
type BalancerConfig struct {
|
||||||
|
|
@ -41,7 +44,15 @@ type BalancerConfig struct {
|
||||||
|
|
||||||
type intermediateBalancerConfig []map[string]json.RawMessage
|
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 {
|
func (bc *BalancerConfig) UnmarshalJSON(b []byte) error {
|
||||||
var ir intermediateBalancerConfig
|
var ir intermediateBalancerConfig
|
||||||
err := json.Unmarshal(b, &ir)
|
err := json.Unmarshal(b, &ir)
|
||||||
|
|
@ -53,13 +64,16 @@ func (bc *BalancerConfig) UnmarshalJSON(b []byte) error {
|
||||||
if len(lbcfg) != 1 {
|
if len(lbcfg) != 1 {
|
||||||
return fmt.Errorf("invalid loadBalancingConfig: entry %v does not contain exactly 1 policy/config pair: %q", i, lbcfg)
|
return fmt.Errorf("invalid loadBalancingConfig: entry %v does not contain exactly 1 policy/config pair: %q", i, lbcfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
name string
|
name string
|
||||||
jsonCfg json.RawMessage
|
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 {
|
for name, jsonCfg = range lbcfg {
|
||||||
}
|
}
|
||||||
|
|
||||||
builder := balancer.Get(name)
|
builder := balancer.Get(name)
|
||||||
if builder == nil {
|
if builder == nil {
|
||||||
// If the balancer is not registered, move on to the next config.
|
// If the balancer is not registered, move on to the next config.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue