From 934303e1b40d96643b29dc40834c069334768266 Mon Sep 17 00:00:00 2001 From: Milos Zivkovic Date: Sat, 16 Sep 2023 20:17:07 +0200 Subject: [PATCH] Improve listen address output --- cmd/serve.go | 2 +- faucet.go | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/serve.go b/cmd/serve.go index e4fca80..471f86c 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -26,7 +26,7 @@ const ( envPrefix = "GNO_FAUCET" ) -var ( +const ( defaultGasFee = "1000000ugnot" defaultGasWanted = "100000" defaultRemote = "http://127.0.0.1:26657" diff --git a/faucet.go b/faucet.go index 7950d10..df59576 100644 --- a/faucet.go +++ b/faucet.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "net" "net/http" "time" @@ -112,15 +113,21 @@ func (f *Faucet) Serve(ctx context.Context) error { group, gCtx := errgroup.WithContext(ctx) group.Go(func() error { + defer f.logger.Info("faucet shut down") + + ln, err := net.Listen("tcp", faucet.Addr) + if err != nil { + return err + } + f.logger.Info( fmt.Sprintf( "faucet started at %s", - f.config.ListenAddress, + ln.Addr().String(), ), ) - defer f.logger.Info("faucet shut down") - if err := faucet.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { + if err := faucet.Serve(ln); err != nil && !errors.Is(err, http.ErrServerClosed) { return err }