removed URL parameter from GetStreamInstant
This commit is contained in:
parent
40fafe91e5
commit
eb8b0d4d61
2 changed files with 15 additions and 8 deletions
2
main.go
2
main.go
|
@ -54,7 +54,7 @@ func (server Server) stream(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
img := stream.GetStreamInstant(URL)
|
img := stream.GetStreamInstant()
|
||||||
mat, err := gocv.IMDecode(img, gocv.IMReadGrayScale)
|
mat, err := gocv.IMDecode(img, gocv.IMReadGrayScale)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Could not IMDecode img")
|
log.Fatal("Could not IMDecode img")
|
||||||
|
|
21
stream.go
21
stream.go
|
@ -28,22 +28,26 @@ func NewStream(URL string) Stream {
|
||||||
Base64: base64,
|
Base64: base64,
|
||||||
Interval: 5000,
|
Interval: 5000,
|
||||||
}
|
}
|
||||||
os.MkdirAll(stream.GetStreamStoreDirPath(), os.ModePerm)
|
|
||||||
stream.WriteStreamJSON()
|
stream.WriteStreamJSON()
|
||||||
return stream
|
return stream
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update calls itself every Interval milliseconds
|
// Update calls itself every Interval milliseconds
|
||||||
func (s Stream) Update() { // TODO make this not overflow, other thing calls this ?
|
func (s Stream) Update() {
|
||||||
log.Print("Update:", s.URL)
|
log.Print("Update:", s.URL)
|
||||||
// TODO make func that does getstreaminstant and savestreaminstant
|
}
|
||||||
time.Sleep(time.Duration(s.Interval) * time.Millisecond)
|
|
||||||
go s.Update()
|
// UpdateInterval calls Update() every interval
|
||||||
|
func (s Stream) UpdateInterval() {
|
||||||
|
for {
|
||||||
|
s.Update()
|
||||||
|
time.Sleep(time.Duration(s.Interval) * time.Millisecond)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStreamInstant http.Get(URL) and returns the response
|
// GetStreamInstant http.Get(URL) and returns the response
|
||||||
func (s Stream) GetStreamInstant(URL string) []byte {
|
func (s Stream) GetStreamInstant() []byte {
|
||||||
resp, err := http.Get(URL)
|
resp, err := http.Get(s.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -90,6 +94,9 @@ func (s Stream) GetStreamJSONPath() string {
|
||||||
|
|
||||||
// WriteStreamJSON writes the Stream struct to GetStreamJSONPath()
|
// WriteStreamJSON writes the Stream struct to GetStreamJSONPath()
|
||||||
func (s Stream) WriteStreamJSON() {
|
func (s Stream) WriteStreamJSON() {
|
||||||
|
if !FileExists(s.GetStreamStoreDirPath()) {
|
||||||
|
os.MkdirAll(s.GetStreamStoreDirPath(), os.ModePerm)
|
||||||
|
}
|
||||||
file, _ := json.MarshalIndent(s, "", "")
|
file, _ := json.MarshalIndent(s, "", "")
|
||||||
_ = ioutil.WriteFile(s.GetStreamJSONPath(), file, 0644)
|
_ = ioutil.WriteFile(s.GetStreamJSONPath(), file, 0644)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue