Skip to content

Commit

Permalink
add http listen addr to config (#230)
Browse files Browse the repository at this point in the history
* go fmt

* add HTTPAddr to config to allow configuring listen address
  • Loading branch information
oliver-nyt authored and jprobinson committed Sep 11, 2019
1 parent 99d516b commit fcf6e85
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions server/kit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion server/kit/kitserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/simple_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit fcf6e85

Please sign in to comment.