moved loading Streams from json to a function
This commit is contained in:
parent
3579788727
commit
27d0297c80
2 changed files with 29 additions and 22 deletions
7
main.go
7
main.go
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
@ -161,10 +160,8 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
streamJSONPath := filepath.Join(GetStreamDirPath(), streamStoreDir.Name(), "stream.json")
|
streamJSONPath := filepath.Join(GetStreamDirPath(), streamStoreDir.Name(), "stream.json")
|
||||||
streamJSONFile, _ := ioutil.ReadFile(streamJSONPath)
|
stream := StreamFromJSON(streamJSONPath)
|
||||||
stream := Stream{}
|
server.Streams[stream.Name] = stream
|
||||||
json.Unmarshal([]byte(streamJSONFile), &stream)
|
|
||||||
server.Streams[stream.Name] = &stream
|
|
||||||
go stream.UpdateInterval()
|
go stream.UpdateInterval()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
44
stream.go
44
stream.go
|
|
@ -36,27 +36,37 @@ func NewStream(Name string, URL string) *Stream {
|
||||||
Interval: 5000,
|
Interval: 5000,
|
||||||
WatchAreas: make([]WatchArea, 0),
|
WatchAreas: make([]WatchArea, 0),
|
||||||
}
|
}
|
||||||
stream.WatchAreas = append(stream.WatchAreas,
|
/*
|
||||||
WatchArea{
|
stream.WatchAreas = append(stream.WatchAreas,
|
||||||
Name: "test",
|
WatchArea{
|
||||||
Color: color.RGBA{255, 0, 255, 255},
|
Name: "test",
|
||||||
Area: image.Rect(30, 30, 400, 200),
|
Color: color.RGBA{255, 0, 255, 255},
|
||||||
},
|
Area: image.Rect(30, 30, 400, 200),
|
||||||
WatchArea{
|
},
|
||||||
Name: "test2",
|
WatchArea{
|
||||||
Color: color.RGBA{0, 255, 255, 255},
|
Name: "test2",
|
||||||
Area: image.Rect(800, 30, 1000, 500),
|
Color: color.RGBA{0, 255, 255, 255},
|
||||||
},
|
Area: image.Rect(800, 30, 1000, 500),
|
||||||
WatchArea{
|
},
|
||||||
Name: "test3",
|
WatchArea{
|
||||||
Color: color.RGBA{255, 255, 0, 255},
|
Name: "test3",
|
||||||
Area: image.Rect(50, 400, 450, 700),
|
Color: color.RGBA{255, 255, 0, 255},
|
||||||
},
|
Area: image.Rect(50, 400, 450, 700),
|
||||||
)
|
},
|
||||||
|
)
|
||||||
|
*/
|
||||||
stream.WriteStreamJSON()
|
stream.WriteStreamJSON()
|
||||||
return &stream
|
return &stream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StreamFromJSON takes a filepath to a JSON file, and returns the unmarshalled Stream object
|
||||||
|
func StreamFromJSON(path string) *Stream {
|
||||||
|
streamJSONFile, _ := ioutil.ReadFile(path)
|
||||||
|
stream := Stream{}
|
||||||
|
json.Unmarshal([]byte(streamJSONFile), &stream)
|
||||||
|
return &stream
|
||||||
|
}
|
||||||
|
|
||||||
// Update gets called by UpdateInterval Interval milliseconds to fetch the latest instant
|
// Update gets called by UpdateInterval Interval milliseconds to fetch the latest instant
|
||||||
func (s *Stream) Update() {
|
func (s *Stream) Update() {
|
||||||
log.Print("Update: ", s.Name, " - ", len(s.WatchAreas), " - ", s.URL)
|
log.Print("Update: ", s.Name, " - ", len(s.WatchAreas), " - ", s.URL)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue