Commit f7e96278 authored by Joan Piles's avatar Joan Piles Committed by root

Read extra schedules from external file. Must be in JSON format

parent 67ca4425
......@@ -193,6 +193,7 @@ func subcmdList() {
func main() {
logger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.Lshortfile)
schedules.AddFromFile("/root/test.sched")
config = LoadConfig()
if config == nil {
log.Fatal("no config, don't know what to do!")
......
......@@ -7,6 +7,9 @@ package main
import (
"strings"
"time"
"encoding/json"
"io/ioutil"
"fmt"
)
const (
......@@ -58,3 +61,21 @@ var schedules = scheduleList{
"testing": {second * 5, second * 20, second * 140, second * 280, long},
"testing2": {second * 5, second * 20, second * 40, second * 80, long},
}
func (schl *scheduleList) AddFromFile(file string) {
schedFile, err := ioutil.ReadFile(file)
if err != nil {
fmt.Printf("Error opening schedule file: %v\n", err)
}
var readData scheduleList
err = json.Unmarshal(schedFile,&readData)
if err != nil {
fmt.Printf("Error parsing data: %v\n", err)
}
for k,v := range readData {
schedules[k] = v
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment