Skip to content

Commit

Permalink
fix json string indentation, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuxuan committed Oct 13, 2017
1 parent d33d38a commit ef70aa1
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 221 deletions.
13 changes: 7 additions & 6 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,13 +793,14 @@ func (cc *ClientConn) getTransport(ctx context.Context, failfast bool) (transpor
// struct ServiceConfig, and store both the struct and the JSON string in ClientConn.
func (cc *ClientConn) handleServiceConfig(js string) error {
sc, err := parseServiceConfig(js)
if err == nil {
cc.mu.Lock()
cc.scRaw = js
cc.sc = sc
cc.mu.Unlock()
if err != nil {
return err
}
return err
cc.mu.Lock()
cc.scRaw = js
cc.sc = sc
cc.mu.Unlock()
return nil
}

// Close tears down the ClientConn and all underlying connections.
Expand Down
39 changes: 0 additions & 39 deletions rpc_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,45 +493,6 @@ func Errorf(c codes.Code, format string, a ...interface{}) error {
return status.Errorf(c, format, a...)
}

// MethodConfig defines the configuration recommended by the service providers for a
// particular method.
// This is EXPERIMENTAL and subject to change.
type MethodConfig struct {
// WaitForReady indicates whether RPCs sent to this method should wait until
// the connection is ready by default (!failfast). The value specified via the
// gRPC client API will override the value set here.
WaitForReady *bool
// Timeout is the default timeout for RPCs sent to this method. The actual
// deadline used will be the minimum of the value specified here and the value
// set by the application via the gRPC client API. If either one is not set,
// then the other will be used. If neither is set, then the RPC has no deadline.
Timeout *time.Duration
// MaxReqSize is the maximum allowed payload size for an individual request in a
// stream (client->server) in bytes. The size which is measured is the serialized
// payload after per-message compression (but before stream compression) in bytes.
// The actual value used is the minimum of the value specified here and the value set
// by the application via the gRPC client API. If either one is not set, then the other
// will be used. If neither is set, then the built-in default is used.
MaxReqSize *int
// MaxRespSize is the maximum allowed payload size for an individual response in a
// stream (server->client) in bytes.
MaxRespSize *int
}

// ServiceConfig is provided by the service provider and contains parameters for how
// clients that connect to the service should behave.
// This is EXPERIMENTAL and subject to change.
type ServiceConfig struct {
// LB is the load balancer the service providers recommends. The balancer specified
// via grpc.WithBalancer will override this.
LB *string
// Methods contains a map for the methods in this service.
// If there is an exact match for a method (i.e. /service/method) in the map, use the corresponding MethodConfig.
// If there's no exact match, look for the default config for the service (/service/) and use the corresponding MethodConfig if it exists.
// Otherwise, the method has no MethodConfig to use.
Methods map[string]MethodConfig
}

func min(a, b *int) *int {
if *a < *b {
return a
Expand Down
43 changes: 41 additions & 2 deletions service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,45 @@ import (
"google.golang.org/grpc/grpclog"
)

// MethodConfig defines the configuration recommended by the service providers for a
// particular method.
// This is EXPERIMENTAL and subject to change.
type MethodConfig struct {
// WaitForReady indicates whether RPCs sent to this method should wait until
// the connection is ready by default (!failfast). The value specified via the
// gRPC client API will override the value set here.
WaitForReady *bool
// Timeout is the default timeout for RPCs sent to this method. The actual
// deadline used will be the minimum of the value specified here and the value
// set by the application via the gRPC client API. If either one is not set,
// then the other will be used. If neither is set, then the RPC has no deadline.
Timeout *time.Duration
// MaxReqSize is the maximum allowed payload size for an individual request in a
// stream (client->server) in bytes. The size which is measured is the serialized
// payload after per-message compression (but before stream compression) in bytes.
// The actual value used is the minimum of the value specified here and the value set
// by the application via the gRPC client API. If either one is not set, then the other
// will be used. If neither is set, then the built-in default is used.
MaxReqSize *int
// MaxRespSize is the maximum allowed payload size for an individual response in a
// stream (server->client) in bytes.
MaxRespSize *int
}

// ServiceConfig is provided by the service provider and contains parameters for how
// clients that connect to the service should behave.
// This is EXPERIMENTAL and subject to change.
type ServiceConfig struct {
// LB is the load balancer the service providers recommends. The balancer specified
// via grpc.WithBalancer will override this.
LB *string
// Methods contains a map for the methods in this service.
// If there is an exact match for a method (i.e. /service/method) in the map, use the corresponding MethodConfig.
// If there's no exact match, look for the default config for the service (/service/) and use the corresponding MethodConfig if it exists.
// Otherwise, the method has no MethodConfig to use.
Methods map[string]MethodConfig
}

func parseTimeout(t *string) (*time.Duration, error) {
if t == nil {
return nil, nil
Expand All @@ -38,7 +77,7 @@ type jsonName struct {
Method *string `json:"method,omitempty"`
}

func (j jsonName) String() (string, bool) {
func (j jsonName) generatePath() (string, bool) {
if j.Service == nil {
return "", false
}
Expand Down Expand Up @@ -94,7 +133,7 @@ func parseServiceConfig(js string) (ServiceConfig, error) {
MaxRespSize: m.MaxResponseMessageBytes,
}
for _, n := range *m.Name {
if path, valid := n.String(); valid {
if path, valid := n.generatePath(); valid {
sc.Methods[path] = mc
}
}
Expand Down
Loading

0 comments on commit ef70aa1

Please sign in to comment.