removed most 'Fatal' usage, so that things keep going when something goes wrong
This commit is contained in:
parent
fd287d7ab8
commit
ddf6ffb4c8
2 changed files with 12 additions and 24 deletions
9
main.go
9
main.go
|
|
@ -24,7 +24,8 @@ func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
|||
if r.FormValue("name") == "" {
|
||||
indexTemplate, err := template.ParseFiles(indexHTML, baseHTML)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
indexTemplate.Execute(w, server.Streams)
|
||||
return
|
||||
|
|
@ -37,7 +38,8 @@ func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
|||
streamTemplate, err := template.ParseFiles(streamHTML, baseHTML)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
streamTemplate.Execute(w, stream)
|
||||
}
|
||||
|
|
@ -67,7 +69,8 @@ func (server Server) addStream(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
addStreamTemplate, err := template.ParseFiles(addStreamHTML, baseHTML)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
addStreamTemplate.Execute(w, struct {
|
||||
NameMessage string
|
||||
|
|
|
|||
27
stream.go
27
stream.go
|
|
@ -72,14 +72,16 @@ func (s *Stream) Update() {
|
|||
log.Print("Update: ", s.Name, " - ", len(s.WatchAreas), " - ", s.URL)
|
||||
resp, err := http.Get(s.URL)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
img, err := ioutil.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
|
||||
mat, err := gocv.IMDecode(img, gocv.IMReadColor)
|
||||
if err != nil {
|
||||
log.Fatal("Could not IMDecode img")
|
||||
log.Println("Could not IMDecode img", err)
|
||||
return
|
||||
}
|
||||
go gocv.IMWrite(s.GetCurrentColorInstantPath(), mat)
|
||||
|
||||
|
|
@ -134,23 +136,6 @@ func (s *Stream) UpdateInterval() {
|
|||
}
|
||||
}
|
||||
|
||||
// GetStreamInstant http.Get(URL) and returns the response
|
||||
func (s *Stream) GetStreamInstant() gocv.Mat {
|
||||
resp, err := http.Get(s.URL)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
img, err := ioutil.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
|
||||
mat, err := gocv.IMDecode(img, gocv.IMReadColor)
|
||||
if err != nil {
|
||||
log.Fatal("Could not IMDecode img")
|
||||
}
|
||||
|
||||
return mat
|
||||
}
|
||||
|
||||
// SaveStreamInstant writes the img to the CurrentStreamInstantPath, moves existing instant to PreviousStreamInstantPath
|
||||
func (s *Stream) SaveStreamInstant(mat gocv.Mat) {
|
||||
s.FileLock.Lock()
|
||||
|
|
@ -176,11 +161,11 @@ func (s *Stream) SaveStreamInstant(mat gocv.Mat) {
|
|||
func (s *Stream) SwapInstants(previous string, current string, next string) {
|
||||
err := os.Rename(current, previous)
|
||||
if err != nil {
|
||||
log.Fatal("Couldn't copy current image instant to previous image instant")
|
||||
log.Println("Couldn't copy current image instant to previous image instant", err)
|
||||
}
|
||||
err = os.Rename(next, current)
|
||||
if err != nil {
|
||||
log.Fatal("Couldn't copy next image instant to current image instant")
|
||||
log.Println("Couldn't copy next image instant to current image instant", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue