Browse Source

fix

tags/version-1.0
Vladimir Smagin 2 months 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 (
7 7
 	"gopkg.in/yaml.v2"
8 8
 )
9 9
 
10
+// readConfigDirectory get contents of target directory
10 11
 func readConfigDirectory(path string) []string {
11 12
 	var res []string
13
+
12 14
 	files, err := ioutil.ReadDir(path)
13 15
 	if err != nil {
14 16
 		log.Fatal(err)
@@ -25,11 +27,14 @@ func readConfigDirectory(path string) []string {
25 27
 // readConfigFile reads config file and returns cronTask struct back to loadConfig()
26 28
 func readConfigFile(path string) cronTask {
27 29
 	var config cronTask
30
+
28 31
 	yamldata, err := ioutil.ReadFile(path)
29 32
 	if err != nil {
30 33
 		log.Fatalf("Error opening file %v", err)
31 34
 	}
32 35
 
36
+	log.Printf(string(yamldata))
37
+
33 38
 	marshErr := yaml.Unmarshal(yamldata, &config)
34 39
 	if marshErr != nil {
35 40
 		log.Fatalf("Error parsing file %v", marshErr)

+ 7
- 5
gogocron.go View File

@@ -12,16 +12,18 @@ type cronTask struct {
12 12
 	runDom    string   `yaml:"runDom,omitempty"`
13 13
 	runMonth  string   `yaml:"runMonth,omitempty"`
14 14
 	runDow    string   `yaml:"runDow,omitempty"`
15
-	command   []string `yaml:"command"`
15
+	commands  []string `yaml:"commands"`
16 16
 }
17 17
 
18
-type cronTaskYaml struct {
19
-	Yaml cronTask
20
-}
18
+type cronTasks []cronTask
21 19
 
22
-func main() {
20
+func loadConfig() {
23 21
 	configs := readConfigDirectory("configs")
24 22
 	log.Printf("Files found: %v", configs)
25 23
 	config := readConfigFile(configs[0])
26 24
 	log.Printf("Parsed %#v", config)
27 25
 }
26
+
27
+func main() {
28
+	loadConfig()
29
+}

Loading…
Cancel
Save