Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove min/max for protocol iteration #93

Merged
merged 8 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

// protocolUnknown is not a valid value. Since it is the zero value, this
// requires that all Protocol values must be explicitly initialized.
protocolUnknown = Protocol(0)

Check failure on line 42 in protocol.go

View workflow job for this annotation

GitHub Actions / ci (1.21.x)

const `protocolUnknown` is unused (unused)
// ProtocolConnect indicates the Connect protocol. This protocol supports
// unary and streaming endpoints. However, bidirectional streams are only
// supported when combined with HTTP/2.
Expand All @@ -66,11 +66,6 @@
// This protocol only supports unary and server-stream endpoints.
ProtocolREST

// protocolMin is the minimum valid value for a Protocol.
protocolMin = ProtocolConnect
// protocolMax is the maximum valid value for a Protocol.
protocolMax = ProtocolREST

protocolNameConnect = "Connect"
protocolNameGRPC = "gRPC"
protocolNameGRPCWeb = "gRPC-Web"
Expand Down
11 changes: 9 additions & 2 deletions transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func (t *Transcoder) registerService(svc *Service, svcOpts serviceOptions) error
return fmt.Errorf("service %s was configured with no target protocols", svc.schema.FullName())
}
for protocol := range svcOpts.protocols {
if protocol <= protocolUnknown || protocol > protocolMax {
switch protocol {
case ProtocolConnect, ProtocolGRPC, ProtocolGRPCWeb, ProtocolREST:
emcfarlane marked this conversation as resolved.
Show resolved Hide resolved
default:
return fmt.Errorf("protocol %d is not a valid value", protocol)
}
}
Expand Down Expand Up @@ -422,7 +424,12 @@ func (o *operation) validate(transcoder *Transcoder) error {
if _, supportsProtocol := o.methodConf.protocols[clientProtoHandler.protocol()]; supportsProtocol {
o.server.protocol = clientProtoHandler.protocol().serverHandler(o)
} else {
for protocol := protocolMin; protocol <= protocolMax; protocol++ {
for _, protocol := range [...]Protocol{
emcfarlane marked this conversation as resolved.
Show resolved Hide resolved
ProtocolConnect,
ProtocolGRPC,
ProtocolGRPCWeb,
ProtocolREST,
} {
if _, supportsProtocol := o.methodConf.protocols[protocol]; supportsProtocol {
o.server.protocol = protocol.serverHandler(o)
break
Expand Down
Loading