diff --git a/internal/app/control.go b/internal/app/control.go index f880c0c..b47f6be 100644 --- a/internal/app/control.go +++ b/internal/app/control.go @@ -7,6 +7,7 @@ package app import ( "context" + "net" "net/http" "time" @@ -34,13 +35,18 @@ func NewHttpServerEntity(bindAddr string) *HttpServerEntity { return &e } -func (e *HttpServerEntity) Start() { - go func() { +func (e *HttpServerEntity) Start() error { + l, err := net.Listen("tcp", e.srv.Addr) + if err != nil { + return err + } + go func(ln net.Listener) { logrus.Info("Starting HTTP Server") - if err := e.srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { + if err := e.srv.Serve(ln); err != nil && err != http.ErrServerClosed { logrus.WithError(err).Error("Http Server error") } - }() + }(l) + return nil } func (e *HttpServerEntity) Stop() { diff --git a/internal/app/setup.go b/internal/app/setup.go index d1428d4..aa7f465 100644 --- a/internal/app/setup.go +++ b/internal/app/setup.go @@ -24,7 +24,9 @@ func NewSetup(config *config.UEConfig) *Setup { } func (s *Setup) Init(ctx context.Context) error { - s.httpServerEntity.Start() + if err := s.httpServerEntity.Start(); err != nil { + return err + } return nil } diff --git a/internal/config/config.go b/internal/config/config.go index 8952ba9..64719ef 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -38,5 +38,5 @@ type UEConfig struct { type Control struct { Uri jsonapi.ControlURI `yaml:"uri"` // may contain domain name instead of ip address - BindAddr string `yaml:"bind-addr"` // in the form `ip` or `ip:port` (with default port being 80) + BindAddr string `yaml:"bind-addr"` // in the form `ip:port` }