first commit

This commit is contained in:
2021-11-02 11:25:21 +01:00
commit 0c861770a8
2162 changed files with 178285 additions and 0 deletions

113
cmd/command.go Normal file
View File

@ -0,0 +1,113 @@
package main
import (
"arno/skeletor/config"
"arno/skeletor/service"
"arno/skeletor/tool"
"arno/skeletor/crontab"
"arno/skeletor/repository"
"arno/skeletor/entity"
"gorm.io/gorm"
"os"
)
func main() {
// Chargement de la configuration
myconfig, mydb, _ := config.NewConfig("config/config.ini", false)
// On s'assure qu'il y a une commande à executer
args := os.Args[1:]
if len(args) == 0 {
Help(mydb)
return
}
// On récupére la commande et ses paramètres
cmd := args[0]
params := args[1:]
// On s'assure que la commande existe bien
var command entity.Command
result := mydb.First(&command, "name = ?", cmd)
if result.RowsAffected == 0 {
Help(mydb)
return
}
// Creation des services
ctn := service.NewContainer()
ctn.Provide(config.ServiceName, config.ServiceProvider(myconfig))
ctn.Provide(repository.ServiceName, repository.ServiceProvider(mydb))
if len(params) == 0 {
_, err := crontab.Call(cmd, ctn)
if err != nil {
tool.LogFatal(err.Error())
tool.LogInfo(command.Name)
tool.Log(command.Description)
tool.Log("")
}
}
if len(params) == 1 {
_, err := crontab.Call(cmd, ctn, params[0])
if err != nil {
tool.LogFatal(err.Error())
tool.LogInfo(command.Name)
tool.Log(command.Description)
tool.Log("")
}
}
if len(params) == 2 {
_, err := crontab.Call(cmd, ctn, params[0], params[1])
if err != nil {
tool.LogFatal(err.Error())
tool.LogInfo(command.Name)
tool.Log(command.Description)
tool.Log("")
}
}
if len(params) == 3 {
_, err := crontab.Call(cmd, ctn, params[0], params[1], params[3])
if err != nil {
tool.LogFatal(err.Error())
}
}
if len(params) == 4 {
_, err := crontab.Call(cmd, ctn, params[0], params[1], params[3], params[4])
if err != nil {
tool.LogFatal(err.Error())
}
}
if len(params) == 5 {
_, err := crontab.Call(cmd, ctn, params[0], params[1], params[3], params[4], params[5])
if err != nil {
tool.LogFatal(err.Error())
}
}
tool.Log("")
}
func Help(mydb *gorm.DB) {
tool.LogTitle("COMMANDES")
tool.Log("Liste des commandes possibles")
tool.Log("")
var commands []entity.Command
mydb.Find(&commands)
for _, command := range commands {
tool.LogInfo(command.Name)
tool.Log(command.Description)
tool.Log("")
}
}

31
cmd/main.go Normal file
View File

@ -0,0 +1,31 @@
package main
import (
"arno/skeletor/config"
"arno/skeletor/middleware"
"arno/skeletor/repository"
"arno/skeletor/service"
"arno/skeletor/tool"
"arno/skeletor/crontab"
)
func main() {
// Chargement de la configuration
tool.LogTitle("INITIALISATION")
myconfig, mydb, _ := config.NewConfig("config/config.ini", true)
// Creation des services
ctn := service.NewContainer()
ctn.Provide(config.ServiceName, config.ServiceProvider(myconfig))
ctn.Provide(repository.ServiceName, repository.ServiceProvider(mydb))
// Execution du Cron
crontab.Lauch(ctn)
// Creation du middleware
tool.LogTitle("MIDDLEWARE")
middleware := middleware.NewMiddleware(ctn)
middleware.StartMiddleware()
}