From a40e5d266f44218ac114526c012504dd39ea74ef Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Tue, 7 May 2024 14:12:58 -0700 Subject: [PATCH] flags: use boolvar; rename default vars --- cmd/mock-da/main.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/cmd/mock-da/main.go b/cmd/mock-da/main.go index a29b16e..e1e9471 100644 --- a/cmd/mock-da/main.go +++ b/cmd/mock-da/main.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "log" - "net/url" "os" "os/signal" "syscall" @@ -15,28 +14,24 @@ import ( ) const ( - // MockDAPort is the port used for the mock DA gRPC server - MockDAPort = 7980 + defaultHost = "localhost" + defaultPort = "7980" ) -var listenAll = flag.Bool("listen-all", false, "Listen on all network interfaces (0.0.0.0) instead of just localhost") - func main() { var ( - host string - port string + host string + port string + listenAll bool ) + flag.StringVar(&port, "port", defaultPort, "listening port") + flag.StringVar(&host, "host", defaultHost, "listening address") + flag.BoolVar(&listenAll, "listen-all", false, "listen on all network interfaces (0.0.0.0) instead of just localhost") flag.Parse() - ip := "localhost" - if *listenAll { - ip = "0.0.0.0" - } - address := fmt.Sprintf("grpc://%s:%d", ip, MockDAPort) - addr, _ := url.Parse(address) - flag.StringVar(&port, "port", addr.Port(), "listening port") - flag.StringVar(&host, "host", addr.Hostname(), "listening address") - flag.Parse() + if listenAll { + host = "0.0.0.0" + } srv := proxy.NewServer(host, port, goDATest.NewDummyDA()) log.Printf("Listening on: %s:%s", host, port)