// Package server // Contain struct and interface for project server package server import ( "context" "fmt" "log/slog" "net/http" "steam_analyzer/internal/config" "time" ) type ILogger interface { Info(msg string, args ...any) Debug(msg string, args ...any) Error(msg string, args ...any) } type Server struct { httpServer *http.Server logger ILogger } type ServerParam struct { Host string Port string Origins []string IdleTimeout time.Duration WriteTimeout time.Duration ReadTimeout time.Duration } func New(cfg config.Server, log ILogger, h http.Handler) *Server { return &Server{ httpServer: &http.Server{ Addr: cfg.Host + ":" + cfg.Port, Handler: configureCORSFor(h, cfg.Origins), // ErrorLog: log, IdleTimeout: cfg.IdleTimeout, WriteTimeout: cfg.WriteTimeout, ReadTimeout: cfg.ReadTimeout, }, logger: log, } } func (s *Server) Run() { s.logger.Info(fmt.Sprintf("Server started at %s", s.httpServer.Addr)) if err := s.httpServer.ListenAndServe(); err != nil { s.logger.Error("Cannot start server", slog.String("error", err.Error())) } } func (s *Server) Stop(ctx context.Context) error { return s.httpServer.Shutdown(ctx) }