refactor: removed error returns where unneeded

This commit is contained in:
Felipe M 2022-08-09 17:44:12 +02:00
parent 065a570525
commit 644174f09a
Signed by: fmartingr
GPG Key ID: 716BC147715E716F
4 changed files with 12 additions and 13 deletions

View File

@ -2,6 +2,7 @@ package main
import (
"context"
"log"
"github.com/fmartingr/bazaar/internal/server"
"github.com/fmartingr/bazaar/pkg/manager"
@ -26,7 +27,9 @@ func main() {
server := server.NewServer(server.ParseServerConfiguration(ctx), &m)
server.Start(ctx)
if err := server.Start(ctx); err != nil {
log.Panicf("error starting server: %s", err)
}
server.WaitStop()
}

View File

@ -50,7 +50,9 @@ func NewHttpServer(port int, m *manager.Manager) *httpServer {
payload, _ := json.Marshal(product)
rw.Header().Add("Content-Type", "application/json")
rw.Write(payload)
if _, err := rw.Write(payload); err != nil {
log.Printf("error writting response: %s", err)
}
})
mux.HandleFunc("/liveness", func(w http.ResponseWriter, r *http.Request) {

View File

@ -36,17 +36,17 @@ func (s *Server) Start(ctx context.Context) error {
return nil
}
func (s *Server) WaitStop() error {
func (s *Server) WaitStop() {
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
sig := <-signals
log.Printf("signal %s received, shutting down", sig)
return s.Stop()
s.Stop()
}
func (s *Server) Stop() error {
func (s *Server) Stop() {
s.cancel()
shuwdownContext, cancel := context.WithTimeout(context.Background(), 10*time.Second)
@ -57,8 +57,6 @@ func (s *Server) Stop() error {
log.Fatalf("error shutting down http server: %s", err)
}
}
return nil
}
func NewServer(conf *ServerConfig, m *manager.Manager) *Server {

View File

@ -14,19 +14,15 @@ type Manager struct {
domains map[string]models.Shop
}
func (m *Manager) Register(domains []string, shopFactory models.ShopFactory) error {
func (m *Manager) Register(domains []string, shopFactory models.ShopFactory) {
baseShop := models.NewShopOptions(clients.NewBasicHttpClient())
shop := shopFactory(baseShop)
for _, domain := range domains {
if _, exists := m.domains[domain]; exists {
return fmt.Errorf("domain %s is already registered", domain)
} else {
if _, exists := m.domains[domain]; !exists {
m.domains[domain] = shop
}
}
return nil
}
func (m *Manager) GetShop(host string) models.Shop {