Skip to content

Commit

Permalink
add "server.http.listen-address" flag and "listenAddress" yaml config…
Browse files Browse the repository at this point in the history
  • Loading branch information
rikimaru0345 committed Nov 27, 2020
1 parent 88627e9 commit ef3fe0d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions rest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type Config struct {
ServerGracefulShutdownTimeout time.Duration `yaml:"gracefulShutdownTimeout"`

HTTPListenAddress string `yaml:"listenAddress"`
HTTPListenPort int `yaml:"listenPort"`
HTTPServerReadTimeout time.Duration `yaml:"readTimeout"`
HTTPServerWriteTimeout time.Duration `yaml:"writeTimeout"`
Expand All @@ -27,6 +28,7 @@ type Config struct {
func (c *Config) RegisterFlags(f *flag.FlagSet) {
f.DurationVar(&c.ServerGracefulShutdownTimeout, "server.graceful-shutdown-timeout", 30*time.Second, "Timeout for graceful shutdowns")

f.StringVar(&c.HTTPListenAddress, "server.http.listen-address", "", "HTTP server listen address")
f.IntVar(&c.HTTPListenPort, "server.http.listen-port", 8080, "HTTP server listen port")
// Get "PORT" environment variable because CloudRun tells us what Port to use
portEnv := os.Getenv("PORT")
Expand Down
2 changes: 1 addition & 1 deletion rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *Server) Start() error {
}()

// Serve HTTP server
listener, err := net.Listen("tcp", net.JoinHostPort("", strconv.Itoa(s.cfg.HTTPListenPort)))
listener, err := net.Listen("tcp", net.JoinHostPort(s.cfg.HTTPListenAddress, strconv.Itoa(s.cfg.HTTPListenPort)))
if err != nil {
return err
}
Expand Down

0 comments on commit ef3fe0d

Please sign in to comment.