From b875e536941135f7995ec3f4defca48de7326db2 Mon Sep 17 00:00:00 2001 From: jc <46619361+juancwu@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:17:14 -0500 Subject: [PATCH] start server in main --- backend/internal/server/index.go | 4 ++-- backend/main.go | 31 +++++++++++++++---------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/backend/internal/server/index.go b/backend/internal/server/index.go index 0d39145..3deeeda 100644 --- a/backend/internal/server/index.go +++ b/backend/internal/server/index.go @@ -51,6 +51,6 @@ func New() (*Server, error) { /* Start the server and binds it to the given port. */ -func (s *Server) Start(port int) error { - return s.Echo.Start(fmt.Sprintf(":%d", port)) +func (s *Server) Start(port string) error { + return s.Echo.Start(fmt.Sprintf(":%s", port)) } diff --git a/backend/main.go b/backend/main.go index 447ff7c..7ac795e 100644 --- a/backend/main.go +++ b/backend/main.go @@ -8,7 +8,7 @@ import ( "github.com/rs/zerolog/log" "KonferCA/SPUR/common" - // "KonferCA/SPUR/internal/server" + "KonferCA/SPUR/internal/server" "github.com/joho/godotenv" ) @@ -24,19 +24,18 @@ func main() { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}) } - // TODO: replaced with new server - // s, err := server.New(false) - // if err != nil { - // log.Fatal().Err(err).Msg("failed to initialized server") - // } - // - // port := os.Getenv("PORT") - // if port == "" { - // port = "8080" - // } - // - // err = s.Listen(":" + os.Getenv("PORT")) - // if err != nil { - // log.Fatal().Err(err).Str("PORT", port).Msg("failed to bind server to start accepting connections.") - // } + s, err := server.New() + if err != nil { + log.Fatal().Err(err).Msg("failed to initialized server") + } + + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + + err = s.Start(port) + if err != nil { + log.Fatal().Err(err).Str("PORT", port).Msg("failed to bind server to start accepting connections.") + } }