Skip to content

Commit

Permalink
Exit on configuration error
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Nov 15, 2024
1 parent 534d271 commit 14388c3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
14 changes: 10 additions & 4 deletions internal/app/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package app

import (
"context"
"net"
"net/http"
"time"

Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion internal/app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}

0 comments on commit 14388c3

Please sign in to comment.