1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00
pasty/internal/consolecommands/cmd_cleanup.go
2023-06-17 21:58:05 +02:00

28 lines
588 B
Go

package consolecommands
import (
"context"
"fmt"
"time"
)
func (router *Router) Cleanup(args []string) {
if len(args) == 0 {
fmt.Println("Expected 1 argument.")
return
}
lifetime, err := time.ParseDuration(args[0])
if err != nil {
fmt.Printf("Could not parse duration: %s.\n", err.Error())
return
}
amount, err := router.Storage.Pastes().DeleteOlderThan(context.Background(), lifetime)
if err != nil {
if err != nil {
fmt.Printf("Could not delete pastes: %s.\n", err.Error())
return
}
}
fmt.Printf("Deleted %d pastes older than %s.\n", amount, lifetime)
}