Skip to content

Commit

Permalink
Feat: configure HTTP server with timeouts for improved reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
kek-Sec committed Dec 20, 2024
1 parent bcb3fdb commit 51f6b39
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main
import (
"log"
"net/http"
"time"

"github.com/kek-Sec/gopherdrop/internal/config"
"github.com/kek-Sec/gopherdrop/internal/database"
Expand All @@ -16,10 +17,28 @@ var version = "dev"
// main initializes configuration, database, and the HTTP server.
func main() {
log.Printf("Starting GopherDrop: %s", version)

// Load configuration
cfg := config.LoadConfig()

// Initialize database
db := database.InitDB(cfg)
db.AutoMigrate(&models.Send{})
go database.CleanupExpired(db)

// Setup router
r := routes.SetupRouter(cfg, db)
log.Fatal(http.ListenAndServe(cfg.ListenAddr, r))

// Configure HTTP server with timeouts
server := &http.Server{
Addr: cfg.ListenAddr,
Handler: r,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second,
}

// Start the server
log.Printf("Listening on %s", cfg.ListenAddr)
log.Fatal(server.ListenAndServe())
}

0 comments on commit 51f6b39

Please sign in to comment.