2020-08-26 23:12:36 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
2021-04-15 20:26:17 +03:00
|
|
|
|
2021-04-15 21:59:32 +03:00
|
|
|
"github.com/lus/pasty/internal/config"
|
2021-04-15 21:15:42 +03:00
|
|
|
"github.com/lus/pasty/internal/shared"
|
2021-04-15 20:26:17 +03:00
|
|
|
"github.com/lus/pasty/internal/storage"
|
2020-08-26 23:12:36 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Validate the command line arguments
|
|
|
|
if len(os.Args) != 3 {
|
|
|
|
panic("Invalid command line arguments")
|
|
|
|
}
|
|
|
|
|
2021-04-15 21:59:32 +03:00
|
|
|
// Load the configuration
|
|
|
|
log.Println("Loading the application configuration...")
|
|
|
|
config.Load()
|
2020-08-26 23:12:36 +03:00
|
|
|
|
|
|
|
// Create and initialize the first (from) driver
|
2021-04-15 21:15:42 +03:00
|
|
|
from, err := storage.GetDriver(shared.StorageType(os.Args[1]))
|
2020-08-26 23:12:36 +03:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
err = from.Initialize()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create and initialize the second (to) driver
|
2021-04-15 21:15:42 +03:00
|
|
|
to, err := storage.GetDriver(shared.StorageType(os.Args[2]))
|
2020-08-26 23:12:36 +03:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
err = to.Initialize()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve a list of IDs from the first (from) driver
|
|
|
|
ids, err := from.ListIDs()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transfer every paste to the second (to) driver
|
|
|
|
for _, id := range ids {
|
|
|
|
log.Println("Transferring ID " + id + "...")
|
|
|
|
|
|
|
|
// Retrieve the paste
|
|
|
|
paste, err := from.Get(id)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("[ERR]", err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the paste
|
|
|
|
err = to.Save(paste)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("[ERR]", err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Transferred ID " + id + ".")
|
|
|
|
}
|
|
|
|
}
|