Repository: grpc/grpc-go
File: rpc_util.go (Go)

Code before:
	}
}

func newAcceptedCompressionConfig(names []string) (*acceptedCompressionConfig, error) {
	cfg := &acceptedCompressionConfig{
		allowed: make(map[string]struct{}, len(names)),
	}
	if len(names) == 0 {
		return cfg, nil
	}
	var ordered []string
	for _, name := range names {
		name = strings.TrimSpace(name)
		if name == "" || name == encoding.Identity {
			continue
		}
		if !grpcutil.IsCompressorNameRegistered(name) {
			return nil, status.Errorf(codes.InvalidArgument, "grpc: compressor %q is not registered", name)
		}
		if _, dup := cfg.allowed[name]; dup {
			continue
		}
		cfg.allowed[name] = struct{}{}
		ordered = append(ordered, name)
	}
	if len(ordered) == 0 {
		return nil, status.Error(codes.InvalidArgument, "grpc: no valid compressor names provided")
	}
	cfg.headerValue = strings.Join(ordered, ",")
	return cfg, nil
}

// CallOption configures a Call before it starts or extracts information from
// a Call after it completes.
type CallOption interface {
	// before is called before the call is sent to any server.  If before
	// returns a non-nil error, the RPC fails with that error.
	before(*callInfo) error

	// after is called after the call has completed.  after cannot return an
	// error, so any failures should be reported via output parameters.
	after(*callInfo, *csAttempt)
}

// EmptyCallOption does not alter the Call configuration.
// It can be embedded in another structure to carry satellite data for use
// by interceptors.
type EmptyCallOption struct{}

func (EmptyCallOption) before(*callInfo) error      { return nil }
func (EmptyCallOption) after(*callInfo, *csAttempt) {}

Review comment (suggestion):
This means you'll get an error if you do `AcceptCompressors("identity")` - that doesn't seem desirable.

Code after:
}

func newAcceptedCompressionConfig(names []string) ([]string, error) {
	if len(names) == 0 {
		return nil, nil
	}
	var allowed []string
	seen := make(map[string]struct{}, len(names))
	for _, name := range names {
		name = strings.TrimSpace(name)
		if name == "" || name == encoding.Identity {
			continue
		}
		if !grpcutil.IsCompressorNameRegistered(name) {
			return nil, status.Errorf(codes.InvalidArgument, "grpc: compressor %q is not registered", name)
		}
		if _, dup := seen[name]; dup {
			continue
		}
		seen[name] = struct{}{}
		allowed = append(allowed, name)
	}
	return allowed, nil
}

// CallOption configures a Call before it starts or extracts information from
// a Call after it completes.
type CallOption interface {
	// before is called before the call is sent to any server.  If before
	// returns a non-nil error, the RPC fails with that error.
	before(*callInfo) error

	// after is called after the call has completed.  after cannot return an
	// error, so any failures should be reported via output parameters.
	after(*callInfo, *csAttempt)
}

// EmptyCallOption does not alter the Call configuration.
// It can be embedded in another structure to carry satellite data for use
// by interceptors.
type EmptyCallOption struct{}

func (EmptyCallOption) before(*callInfo) error      { return nil }
func (EmptyCallOption) after(*callInfo, *csAttempt) {}

// StaticMethod returns a CallOption which specifies that a call is being made
// to a method that is static, which means the method is known at compile time
// and doesn't change at runtime. This can be used as a signal to stats plugins
// that this method is safe to include as a key to a measurement.
func StaticMethod() CallOption {
	return StaticMethodCallOption{}