datawriter/internal/app/app.go

82 lines
1.8 KiB
Go

package app
import (
"context"
"io/fs"
"os"
"runtime"
"sync"
"gittea.marcokittel.de/elio/eliotools/datawriter/internal/dbwriter"
"gittea.marcokittel.de/elio/eliotools/logger"
"gittea.marcokittel.de/elio/eliotools/tools"
)
type App struct {
wg *sync.WaitGroup
mu sync.Mutex
log logger.Logger
newFolderPath string
processedFolderPath string
lookupPath string
dirCreationRights int
}
func NewApp(newFolderPath string, processedFolderPath string, dirCreationRights int, wg *sync.WaitGroup) *App {
a := App{log: logger.NewMarcoLogger(),
newFolderPath: newFolderPath,
processedFolderPath: processedFolderPath,
dirCreationRights: dirCreationRights,
wg: wg,
}
return &a
}
func (a *App) HandleData(ctx context.Context, data dbwriter.MyStruct) error {
a.log.Info("HandleData")
return nil
}
func (a *App) AppendData(data dbwriter.MyStruct) error {
a.log.Info("Verarbeite Daten: " + data.A + " " + string(data.B))
//Todo
return nil
}
func (a *App) Foo() {
path, _ := os.Getwd()
ml := logger.NewMarcoLogger()
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")
}