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

28 lines
588 B
Go
Raw Permalink Normal View History

package consolecommands
2023-06-17 22:52:09 +03:00
import (
"context"
"fmt"
"time"
)
func (router *Router) Cleanup(args []string) {
2023-06-17 22:52:09 +03:00
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)
}