2020-08-22 23:13:43 +03:00
|
|
|
package main
|
|
|
|
|
2020-08-23 01:06:29 +03:00
|
|
|
import (
|
|
|
|
"log"
|
2020-09-19 02:56:50 +03:00
|
|
|
"time"
|
2021-04-15 20:26:17 +03:00
|
|
|
|
2021-04-15 21:15:42 +03:00
|
|
|
"github.com/lus/pasty/internal/config"
|
2021-04-15 20:26:17 +03:00
|
|
|
"github.com/lus/pasty/internal/storage"
|
|
|
|
"github.com/lus/pasty/internal/web"
|
2020-08-23 01:06:29 +03:00
|
|
|
)
|
2020-08-23 00:24:38 +03:00
|
|
|
|
2020-08-22 23:13:43 +03:00
|
|
|
func main() {
|
2021-04-15 21:15:42 +03:00
|
|
|
// Load the configuration
|
|
|
|
log.Println("Loading the application configuration...")
|
|
|
|
config.Load()
|
2020-08-23 01:06:29 +03:00
|
|
|
|
|
|
|
// Load the configured storage driver
|
|
|
|
log.Println("Loading the configured storage driver...")
|
|
|
|
err := storage.Load()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-08-24 19:08:27 +03:00
|
|
|
defer func() {
|
|
|
|
log.Println("Terminating the storage driver...")
|
|
|
|
err := storage.Current.Terminate()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
}()
|
2020-08-23 01:06:29 +03:00
|
|
|
|
2020-09-19 02:56:50 +03:00
|
|
|
// Schedule the AutoDelete task
|
2021-04-15 21:15:42 +03:00
|
|
|
if config.Current.AutoDelete.Enabled {
|
2020-09-19 02:56:50 +03: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 21:15:42 +03:00
|
|
|
time.Sleep(config.Current.AutoDelete.TaskInterval)
|
2020-09-19 02:56:50 +03:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2020-08-23 17:44:06 +03:00
|
|
|
// Serve the web resources
|
|
|
|
log.Println("Serving the web resources...")
|
2020-08-23 01:32:46 +03:00
|
|
|
panic(web.Serve())
|
2020-08-22 23:13:43 +03:00
|
|
|
}
|