package main import ( "context" "log" "net/http" "os" "os/signal" "perler-beads-server/internal/server" "syscall" "time" ) func main() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) s, e := server.New(ctx) cancel() if e != nil { log.Fatal(e) } defer s.DB.Close() defer s.Redis.Close() addr := os.Getenv("LISTEN_ADDR") if addr == "" { addr = ":8080" } h := &http.Server{Addr: addr, Handler: s.Router(), ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 15 * time.Second, WriteTimeout: 30 * time.Second, IdleTimeout: 60 * time.Second} go func() { if e := h.ListenAndServe(); e != nil && e != http.ErrServerClosed { log.Fatal(e) } }() quit := make(chan os.Signal, 1) signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) <-quit ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second) defer cancel() s.CloseWebSockets() h.Shutdown(ctx) }