ft-sync/cmd/action/initcmd/process.go
2024-08-27 23:46:37 +02:00

42 lines
900 B
Go

package initcmd
import (
"log"
"os"
filestore "gitnet.fr/deblan/freetube-sync/store/file"
"gitnet.fr/deblan/freetube-sync/web/client"
"gitnet.fr/deblan/freetube-sync/web/route"
)
func Process(name, route string, data any) bool {
log.Print("Init of " + name)
response, err := client.Init(route, data)
res := true
if err != nil {
log.Print("Error while initializing " + name + ": " + err.Error())
res = false
} else {
if response.Code == 201 {
log.Print(name + " initialized!")
} else {
log.Print("Error while initializing " + name + ": " + response.Message)
res = false
}
}
return res
}
func Run() {
a := Process("history", route.HistoryInit, filestore.LoadHistory())
b := Process("playlists", route.PlaylistInit, filestore.LoadPlaylists())
c := Process("profiles", route.ProfileInit, filestore.LoadProfiles())
if a && b && c {
os.Exit(0)
}
os.Exit(1)
}