App struct hinzugefügt um Mutex usw später zu handeln
This commit is contained in:
parent
8417e8a888
commit
6daf06d19c
|
|
@ -1,12 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"gittea.marcokittel.de/elio/eliotools/datawriter/internal/app"
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"gittea.marcokittel.de/elio/eliotools/logger"
|
|
||||||
"gittea.marcokittel.de/elio/eliotools/tools"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -19,37 +14,9 @@ const (
|
||||||
var filename = "2023-11-09T15:02:17+00:00-CH-stock.csv"
|
var filename = "2023-11-09T15:02:17+00:00-CH-stock.csv"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
x := tools.IsFilenameValid(filename)
|
|
||||||
|
|
||||||
ml := logger.NewMarcoLogger()
|
// Auf mdcat warten
|
||||||
ml.Info(fmt.Sprint(x))
|
app := app.NewApp(NewDir, ProcessedDir, Rights)
|
||||||
if runtime.GOOS == "windows" {
|
app.Run()
|
||||||
ml.Fatal("Einfach nein!")
|
|
||||||
}
|
|
||||||
path, _ := os.Getwd()
|
|
||||||
|
|
||||||
newDirExists, err := tools.CheckDir(path + NewDir)
|
|
||||||
if err != nil {
|
|
||||||
ml.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
processedDirExists, err := tools.CheckDir(path + ProcessedDir)
|
|
||||||
if err != nil {
|
|
||||||
ml.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if !newDirExists {
|
|
||||||
err := tools.Createdir(path+NewDir, Rights)
|
|
||||||
if err == nil {
|
|
||||||
ml.Infof("%s created.", path+NewDir)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !processedDirExists {
|
|
||||||
err := tools.Createdir(path+ProcessedDir, Rights)
|
|
||||||
if err == nil {
|
|
||||||
ml.Infof("%s created.", path+ProcessedDir)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,89 @@
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gittea.marcokittel.de/elio/eliotools/logger"
|
||||||
|
"gittea.marcokittel.de/elio/eliotools/tools"
|
||||||
|
)
|
||||||
|
|
||||||
|
type App struct {
|
||||||
|
wg sync.WaitGroup
|
||||||
|
log logger.Logger
|
||||||
|
newFolderPath string
|
||||||
|
processedFolderPath string
|
||||||
|
lookupPath string
|
||||||
|
dirCreationRights int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApp(newFolderPath string, processedFolderPath string, dirCreationRights int) *App {
|
||||||
|
a := App{log: logger.NewMarcoLogger(),
|
||||||
|
newFolderPath: newFolderPath,
|
||||||
|
processedFolderPath: processedFolderPath,
|
||||||
|
dirCreationRights: dirCreationRights,
|
||||||
|
}
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) Foo() {
|
||||||
|
|
||||||
|
// x := tools.IsFilenameValid(filename)
|
||||||
|
path, _ := os.Getwd()
|
||||||
|
|
||||||
|
ml := logger.NewMarcoLogger()
|
||||||
|
// ml.Info(fmt.Sprint(x))
|
||||||
|
|
||||||
|
newDirExists, err := tools.CheckDir(path + a.newFolderPath)
|
||||||
|
if err != nil {
|
||||||
|
ml.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
processedDirExists, err := tools.CheckDir(path + a.processedFolderPath)
|
||||||
|
if err != nil {
|
||||||
|
ml.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if !newDirExists {
|
||||||
|
err := tools.Createdir(path+a.newFolderPath, fs.FileMode(a.dirCreationRights))
|
||||||
|
if err == nil {
|
||||||
|
ml.Infof("%s created.", a.newFolderPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !processedDirExists {
|
||||||
|
err := tools.Createdir(path+a.processedFolderPath, fs.FileMode(a.dirCreationRights))
|
||||||
|
if err == nil {
|
||||||
|
ml.Infof("%s created.", a.processedFolderPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) Run() {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
a.log.Fatal("Einfach nein!")
|
||||||
|
}
|
||||||
|
|
||||||
|
a.log.Info("Applikation gestartet")
|
||||||
|
for {
|
||||||
|
|
||||||
|
time.Sleep(time.Second * 10)
|
||||||
|
a.log.Info("Oh yeah baby, wir nehmen fahrt auf...")
|
||||||
|
}
|
||||||
|
// Todo:
|
||||||
|
// for i := 0; i < 4; i++ {
|
||||||
|
// a.wg.Add(1)
|
||||||
|
// go func() {
|
||||||
|
// defer a.wg.Done()
|
||||||
|
|
||||||
|
// ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Duration(1*time.Millisecond)))
|
||||||
|
// defer cancel()
|
||||||
|
|
||||||
|
// }()
|
||||||
|
// }
|
||||||
|
// a.wg.Wait()
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue