From fcf6e85e81166b1b06e72fb767a21d65c6d290b8 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 11 Sep 2019 09:40:36 -0400 Subject: [PATCH] add http listen addr to config (#230) * go fmt * add HTTPAddr to config to allow configuring listen address --- pubsub/pubsub.go | 2 +- server/config.go | 2 ++ server/kit/config.go | 3 +++ server/kit/kitserver.go | 2 +- server/simple_server.go | 2 +- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pubsub/pubsub.go b/pubsub/pubsub.go index f61131204..6746c19ab 100644 --- a/pubsub/pubsub.go +++ b/pubsub/pubsub.go @@ -5,8 +5,8 @@ import ( "golang.org/x/net/context" - "github.com/sirupsen/logrus" "github.com/golang/protobuf/proto" + "github.com/sirupsen/logrus" ) // Log is the structured logger used throughout the package. diff --git a/server/config.go b/server/config.go index df36b6e06..a532efde5 100644 --- a/server/config.go +++ b/server/config.go @@ -56,6 +56,8 @@ type Config struct { // no access logging will be done. RPCAccessLog *string `envconfig:"RPC_ACCESS_LOG"` + // HTTPAddr is the address the server implementation will bind to. + HTTPAddr string `envconfig:"HTTP_ADDR"` // HTTPPort is the port the server implementation will serve HTTP over. HTTPPort int `envconfig:"HTTP_PORT"` // RPCPort is the port the server implementation will serve RPC over. diff --git a/server/kit/config.go b/server/kit/config.go index 4d268fd16..e5e59e7b5 100644 --- a/server/kit/config.go +++ b/server/kit/config.go @@ -40,6 +40,9 @@ type Config struct { // GOMAXPROCS can be used to override the default GOMAXPROCS. GOMAXPROCS int `envconfig:"GIZMO_GOMAXPROCS"` + // HTTPAddr is the address the server implementation will bind to. + // The default is "" (bind to all interfaces) + HTTPAddr string `envconfig:"HTTP_ADDR"` // HTTPPort is the port the server implementation will serve HTTP over. // The default is 8080 HTTPPort int `envconfig:"HTTP_PORT"` diff --git a/server/kit/kitserver.go b/server/kit/kitserver.go index d2c183c44..de95d0238 100644 --- a/server/kit/kitserver.go +++ b/server/kit/kitserver.go @@ -148,7 +148,7 @@ func NewServer(svc Service) *Server { } s.svr = &http.Server{ Handler: &ochttp.Handler{Handler: s, Propagation: propr}, - Addr: fmt.Sprintf(":%d", cfg.HTTPPort), + Addr: fmt.Sprintf("%s:%d", cfg.HTTPAddr, cfg.HTTPPort), MaxHeaderBytes: cfg.MaxHeaderBytes, ReadTimeout: cfg.ReadTimeout, WriteTimeout: cfg.WriteTimeout, diff --git a/server/simple_server.go b/server/simple_server.go index d92f65363..11056ebb0 100644 --- a/server/simple_server.go +++ b/server/simple_server.go @@ -137,7 +137,7 @@ func (s *SimpleServer) Start() error { srv := httpServer(wrappedHandler) - l, err := net.Listen("tcp", fmt.Sprintf(":%d", s.cfg.HTTPPort)) + l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.cfg.HTTPAddr, s.cfg.HTTPPort)) if err != nil { return err }