2020-08-22 20:13:43 +00:00
|
|
|
package main
|
|
|
|
|
2020-08-22 22:06:29 +00:00
|
|
|
import (
|
|
|
|
"log"
|
2020-09-18 23:56:50 +00:00
|
|
|
"time"
|
2021-04-15 17:26:17 +00:00
|
|
|
|
2021-04-15 18:15:42 +00:00
|
|
|
"github.com/lus/pasty/internal/config"
|
2021-04-15 17:26:17 +00:00
|
|
|
"github.com/lus/pasty/internal/storage"
|
|
|
|
"github.com/lus/pasty/internal/web"
|
2020-08-22 22:06:29 +00:00
|
|
|
)
|
2020-08-22 21:24:38 +00:00
|
|
|
|
2020-08-22 20:13:43 +00:00
|
|
|
func main() {
|
2021-04-15 18:15:42 +00:00
|
|
|
// Load the configuration
|
|
|
|
log.Println("Loading the application configuration...")
|
|
|
|
config.Load()
|
2020-08-22 22:06:29 +00:00
|
|
|
|
|
|
|
// Load the configured storage driver
|
|
|
|
log.Println("Loading the configured storage driver...")
|
|
|
|
err := storage.Load()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-08-24 16:08:27 +00:00
|
|
|
defer func() {
|
|
|
|
log.Println("Terminating the storage driver...")
|
|
|
|
err := storage.Current.Terminate()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
}()
|
2020-08-22 22:06:29 +00:00
|
|
|
|
2020-09-18 23:56:50 +00:00
|
|
|
// Schedule the AutoDelete task
|
2021-04-15 18:15:42 +00:00
|
|
|
if config.Current.AutoDelete.Enabled {
|
2020-09-18 23:56:50 +00:00
|
|
|
log.Println("Scheduling the AutoDelete task...")
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
// Run the cleanup sequence
|
|
|
|
deleted, err := storage.Current.Cleanup()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
log.Printf("AutoDelete: Deleted %d expired pastes", deleted)
|
|
|
|
|
|
|
|
// Wait until the process should repeat
|
2021-04-15 18:15:42 +00:00
|
|
|
time.Sleep(config.Current.AutoDelete.TaskInterval)
|
2020-09-18 23:56:50 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2020-08-23 14:44:06 +00:00
|
|
|
// Serve the web resources
|
|
|
|
log.Println("Serving the web resources...")
|
2020-08-22 22:32:46 +00:00
|
|
|
panic(web.Serve())
|
2020-08-22 20:13:43 +00:00
|
|
|
}
|