2024-04-04 01:12:42 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-04-08 03:22:47 +02:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
|
2024-04-08 03:56:21 +02:00
|
|
|
"git.gnous.eu/ada/spiegel/internal/config"
|
|
|
|
"git.gnous.eu/ada/spiegel/internal/cron"
|
|
|
|
"git.gnous.eu/ada/spiegel/internal/git"
|
2024-05-26 22:00:55 +02:00
|
|
|
"git.gnous.eu/ada/spiegel/internal/router"
|
2024-04-04 01:12:42 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-05-22 01:45:19 +02:00
|
|
|
var configPath string
|
|
|
|
|
|
|
|
switch len(os.Args) {
|
|
|
|
case 2: //nolint:mnd
|
|
|
|
configPath = os.Args[1]
|
|
|
|
case 1:
|
|
|
|
configPath = "config.toml"
|
|
|
|
default:
|
|
|
|
logrus.Fatal("Max 1 argument is valid.")
|
|
|
|
}
|
|
|
|
|
|
|
|
initConfig, err := config.LoadToml(configPath)
|
2024-04-04 01:12:42 +02:00
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2024-04-04 18:02:04 +02:00
|
|
|
err = initConfig.Verify()
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2024-04-04 01:12:42 +02:00
|
|
|
initConfig.Log.Init()
|
|
|
|
logrus.Info("Config loaded")
|
|
|
|
logrus.Debug("Config: ", initConfig)
|
2024-04-04 18:02:04 +02:00
|
|
|
|
2024-05-26 22:00:55 +02:00
|
|
|
routerConfig := router.Config{Listen: ":3000", Archive: initConfig.CloneDirectory}
|
|
|
|
go routerConfig.Router()
|
|
|
|
|
2024-04-04 20:53:35 +02:00
|
|
|
git.StartClone(initConfig.RepoList)
|
2024-04-08 03:22:47 +02:00
|
|
|
|
2024-05-22 01:58:15 +02:00
|
|
|
duration := time.Duration(initConfig.Interval) * time.Minute
|
|
|
|
cron.Launch(duration, initConfig.RepoList)
|
2024-04-08 03:22:47 +02:00
|
|
|
|
|
|
|
quitSignal := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(quitSignal, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
<-quitSignal
|
|
|
|
logrus.Info("Bye!")
|
2024-04-04 01:12:42 +02:00
|
|
|
}
|