Browse Source

fix

tags/version-1.0
Vladimir Smagin 1 year ago
parent
commit
839570c7a7
2 changed files with 12 additions and 5 deletions
  1. 5
    0
      file_utils.go
  2. 7
    5
      gogocron.go

+ 5
- 0
file_utils.go View File

@@ -7,8 +7,10 @@ import (
"gopkg.in/yaml.v2"
)

// readConfigDirectory get contents of target directory
func readConfigDirectory(path string) []string {
var res []string

files, err := ioutil.ReadDir(path)
if err != nil {
log.Fatal(err)
@@ -25,11 +27,14 @@ func readConfigDirectory(path string) []string {
// readConfigFile reads config file and returns cronTask struct back to loadConfig()
func readConfigFile(path string) cronTask {
var config cronTask

yamldata, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalf("Error opening file %v", err)
}

log.Printf(string(yamldata))

marshErr := yaml.Unmarshal(yamldata, &config)
if marshErr != nil {
log.Fatalf("Error parsing file %v", marshErr)

+ 7
- 5
gogocron.go View File

@@ -12,16 +12,18 @@ type cronTask struct {
runDom string `yaml:"runDom,omitempty"`
runMonth string `yaml:"runMonth,omitempty"`
runDow string `yaml:"runDow,omitempty"`
command []string `yaml:"command"`
commands []string `yaml:"commands"`
}

type cronTaskYaml struct {
Yaml cronTask
}
type cronTasks []cronTask

func main() {
func loadConfig() {
configs := readConfigDirectory("configs")
log.Printf("Files found: %v", configs)
config := readConfigFile(configs[0])
log.Printf("Parsed %#v", config)
}

func main() {
loadConfig()
}

Loading…
Cancel
Save