Skip to content

Commit

Permalink
feat: run EvictOldLinks function in separate goroutine after every 1 …
Browse files Browse the repository at this point in the history
…hour
  • Loading branch information
Hamza12700 committed Nov 29, 2024
1 parent 33850fa commit fbca696
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ func main() {
// Get the env variables and other config options
config.Init()

go validate.EvictOldLinks(2)

// Create the URLs table in the database
db := utils.ConnectDB()
err := database.New(db).CreateUrlTable(context.Background())
asserts.NoErr(err, "Failed to create the URLs table in the database")
db.Close()

// Find and remove links that are older than a month every hour
go func() {
for {
validate.EvictOldLinks(db)
time.Sleep(60 * time.Minute)
}
}()

// Serving static files with caching
router.Handle("GET /static/", http.StripPrefix("/static/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Set Cache-Control headers for 10 days
Expand Down

0 comments on commit fbca696

Please sign in to comment.