Skip to content

Commit

Permalink
Make each server optional
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Jun 6, 2024
1 parent 8d1820b commit 8aeb230
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions cmd-rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ func newCmd_rpc() *cli.Command {
&cli.StringFlag{
Name: "listen",
Usage: "Listen address",
Value: ":8899",
Value: "", // If empty, JSON RPC server is not started
Destination: &listenOn,
},
&cli.StringFlag{
Name: "grpc-listen",
Usage: "Listen address for gRPC",
Value: ":8898",
Value: "", // If empty, gRPC server is not started
Destination: &grpcListenOn,
},
&cli.BoolFlag{
Expand Down Expand Up @@ -104,6 +104,9 @@ func newCmd_rpc() *cli.Command {
},
),
Action: func(c *cli.Context) error {
if listenOn == "" && grpcListenOn == "" {
return cli.Exit("either --listen or --grpc-listen must be provided (or both)", 1)
}
src := c.Args().Slice()
configFiles, err := GetListOfConfigFiles(
src,
Expand Down Expand Up @@ -331,13 +334,15 @@ func newCmd_rpc() *cli.Command {
return nil
})
}
allListeners.Go(func() error {
err := multi.ListenAndServe(c.Context, listenOn, listenerConfig)
if err != nil {
return fmt.Errorf("failed to start JSON RPC server: %w", err)
}
return nil
})
if listenOn != "" {
allListeners.Go(func() error {
err := multi.ListenAndServe(c.Context, listenOn, listenerConfig)
if err != nil {
return fmt.Errorf("failed to start JSON RPC server: %w", err)
}
return nil
})
}

return allListeners.Wait()
},
Expand Down

0 comments on commit 8aeb230

Please sign in to comment.