Create JSON modell

wip
Jonas Letzbor 2022-09-22 19:45:33 +02:00
parent fac781a053
commit 91f2e1abcb
6 changed files with 91 additions and 3 deletions

View File

@ -0,0 +1,21 @@
{
"users": [
{
"authUser": "Unique Username (from ",
"nextcloudUrl": "https://cloud.myDomain.de",
"username": "MyUsername",
"password": "App Password",
"jobs": [
{
"jobName": "",
"sourceDir": "Arbeit/",
"destinationDir": "Ebooks/",
"keepFolders": true,
"recursive": true,
"execution": [ "01:00", "15:00" ]
}
]
}
]
}

View File

@ -0,0 +1,49 @@
package models
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
type User struct {
AuthUser string`json:"authUser"`
NextcloudBaseUrl string`json:"nextcloudUrl"`
Username string`json:"username"`
Password string`json:"password"`
}
type ConvertJob struct {
JobName string`json:"jobName"`
SourceDir string`json:"sourceDir"`
DestinationDir string`json:"destinationDir"`
KeepFolders string`json:"keepFolders"`
Recursive string`json:"recursive"`
Executions []string`json:"execution"`
}
type NcConverter struct {
Users []User`json:"users"`
}
// Parses the given file to the in memory struct
func ParseUsers(filePath string) (*NcConverter, error) {
file, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, fmt.Errorf("failed to open the file '%s': %s", filePath, err)
}
defer file.Close()
byteValue, err := ioutil.ReadAll(file)
if err != nil {
return nil, fmt.Errorf("failed to parse 'ncConverter.json': %s", err)
}
var conv NcConverter
json.Unmarshal(byteValue, &conv)
return &conv, nil
}

View File

@ -2,7 +2,6 @@ package models
import (
"flag"
"fmt"
"os"
yaml "gopkg.in/yaml.v3"
@ -27,6 +26,7 @@ type Logging struct {
LogFilePath string `yaml:"logFilePath"`
}
// Parses the given configuration file (.yaml file) to an WebConfiguration
func ParseConfig(webConfig *WebConfig, file string) (*WebConfig, error) {
if file == "" {
return webConfig, nil
@ -70,7 +70,9 @@ func SetConfig() (*WebConfig, error) {
webConfig := getDefaultConfig()
webConfig, err := ParseConfig(webConfig, configPath)
if err != nil {
return nil, fmt.Errorf("unable to parse the configuration file '%s': %s", configPath, err)
logger.Error("Unable to parse the configuration file '%s': %s", configPath, err)
webConfig = getDefaultConfig()
err = nil
}
_ = flag.String("config", "./config.yaml", "Path to the configuration file (see configs/config.yaml) for an example")

View File

@ -0,0 +1,9 @@
package ncworker
type NcConverter struct {
NextcloudBaseUrl string`json:"nextcloudUrl"`
Username string`json:"username"`
App
SourceDir string`json:"users"`
DestinationDir string`json:"users"`
}

View File

@ -0,0 +1,7 @@
package ncworker
func scheduleExecutions() {
}

2
scripts/run.sh 100644 → 100755
View File

@ -1,3 +1,3 @@
#!/bin/sh
nodemon --delay 1s -e go,html --ignore web/app/ --exec go run ./cmd/ncDocConverth --signal SIGTERM
./web/app/node_modules/.bin/nodemon --delay 10s -e go,html --ignore web/app/ --signal SIGTERM --exec go run ./cmd/ncDocConverth || exit 1