@@ -144,15 +144,13 @@ func Listen(ctx context.Context, opts ListenOpts, registerServices func(Server))
144144 return err
145145 }
146146
147- listeners := map [string ]net.Listener {}
148147 for _ , cfg := range rt .ListenerConfiguration {
149148 c := listenerConfiguration (cfg .Name )
150149 if c == nil {
151150 return fnerrors .New ("missing listener configuration for %q" , cfg .Name )
152151 }
153152
154- switch cfg .Protocol {
155- case "grpc" :
153+ if cfg .Protocol == "grpc" {
156154 if cgrp , ok := c .(GrpcListenerConfiguration ); ok {
157155 x := append (slices .Clone (grpcopts ), cgrp .ServerOpts (cfg .Name )... )
158156 if creds := cgrp .TransportCredentials (cfg .Name ); creds != nil {
@@ -170,16 +168,7 @@ func Listen(ctx context.Context, opts ListenOpts, registerServices func(Server))
170168 } else {
171169 return fnerrors .New ("listener configuration for %q does not support grpc" , cfg .Name )
172170 }
173-
174- case "" :
175- lst , err := c .CreateListener (ctx , cfg .Name , opts )
176- if err != nil {
177- return err
178- }
179-
180- listeners [cfg .Name ] = lst
181-
182- default :
171+ } else if cfg .Protocol != "" {
183172 return fnerrors .New ("unsupported service protocol %q" , cfg .Protocol )
184173 }
185174 }
@@ -266,9 +255,20 @@ func Listen(ctx context.Context, opts ListenOpts, registerServices func(Server))
266255 eg .Go (func () error { return ignoreClosure ("grpc" , m .Serve ()) })
267256
268257 for _ , reg := range s .listeners {
269- lst := listeners [reg .ConfigurationName ]
270- if lst == nil {
271- return fnerrors .New ("%q registered for a listener with %q, but there's none" , reg .PackageName , reg .ConfigurationName )
258+ var c ListenerConfiguration
259+ for _ , cfg := range rt .ListenerConfiguration {
260+ if cfg .Name == reg .ConfigurationName {
261+ if cfg .Protocol != "" {
262+ return fnerrors .New ("listener can't have a bound protocol (saw %q)" , cfg .Protocol )
263+ }
264+
265+ c = listenerConfiguration (cfg .Name )
266+ }
267+ }
268+
269+ lst , err := c .CreateListener (ctx , reg .ConfigurationName , opts )
270+ if err != nil {
271+ return err
272272 }
273273
274274 reg := reg // Close reg.
0 commit comments