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
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"image"
|
||||
"image/color"
|
||||
"io/ioutil"
|
||||
|
|
@ -161,10 +160,8 @@ func main() {
|
|||
}
|
||||
|
||||
streamJSONPath := filepath.Join(GetStreamDirPath(), streamStoreDir.Name(), "stream.json")
|
||||
streamJSONFile, _ := ioutil.ReadFile(streamJSONPath)
|
||||
stream := Stream{}
|
||||
json.Unmarshal([]byte(streamJSONFile), &stream)
|
||||
server.Streams[stream.Name] = &stream
|
||||
stream := StreamFromJSON(streamJSONPath)
|
||||
server.Streams[stream.Name] = stream
|
||||
go stream.UpdateInterval()
|
||||
}
|
||||
|
||||
|
|
|
|||
10
stream.go
10
stream.go
|
|
@ -36,6 +36,7 @@ func NewStream(Name string, URL string) *Stream {
|
|||
Interval: 5000,
|
||||
WatchAreas: make([]WatchArea, 0),
|
||||
}
|
||||
/*
|
||||
stream.WatchAreas = append(stream.WatchAreas,
|
||||
WatchArea{
|
||||
Name: "test",
|
||||
|
|
@ -53,10 +54,19 @@ func NewStream(Name string, URL string) *Stream {
|
|||
Area: image.Rect(50, 400, 450, 700),
|
||||
},
|
||||
)
|
||||
*/
|
||||
stream.WriteStreamJSON()
|
||||
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
|
||||
func (s *Stream) Update() {
|
||||
log.Print("Update: ", s.Name, " - ", len(s.WatchAreas), " - ", s.URL)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue