added some comments to main.go
This commit is contained in:
parent
bbb4392783
commit
8c29d47eeb
1 changed files with 10 additions and 1 deletions
11
main.go
11
main.go
|
|
@ -20,10 +20,12 @@ var streamHTML = filepath.Join("templates", "stream.html")
|
|||
var momentsHTML = filepath.Join("templates", "moments.html")
|
||||
|
||||
// Server is the main application struct
|
||||
// It holds a map[string]*Stream that contains all the Stream objects
|
||||
type Server struct {
|
||||
Streams map[string]*Stream
|
||||
}
|
||||
|
||||
// index shows a table of available streams or when visited with a 'name' param, the stream with that name.
|
||||
func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
||||
if r.FormValue("name") == "" {
|
||||
indexTemplate, err := template.ParseFiles(indexHTML, baseHTML)
|
||||
|
|
@ -58,6 +60,7 @@ func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
|||
})
|
||||
}
|
||||
|
||||
// addStream adds the POSTed Stream to Server.Streams
|
||||
func (server Server) addStream(w http.ResponseWriter, r *http.Request) {
|
||||
nameMessage := ""
|
||||
URLMessage := ""
|
||||
|
|
@ -126,6 +129,7 @@ func (server Server) addStream(w http.ResponseWriter, r *http.Request) {
|
|||
})
|
||||
}
|
||||
|
||||
// addWatchArea adds the POSTed WatchArea to Stream.WatchAreas
|
||||
func (server Server) addWatchArea(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "POST" {
|
||||
return
|
||||
|
|
@ -188,6 +192,7 @@ func (server Server) addWatchArea(w http.ResponseWriter, r *http.Request) {
|
|||
http.Redirect(w, r, "/?name="+streamName, http.StatusTemporaryRedirect)
|
||||
}
|
||||
|
||||
// streamRecordings shows a table of 'moments', a continuous series of motion detected instants
|
||||
func (server Server) streamRecordings(w http.ResponseWriter, r *http.Request) {
|
||||
streamName := r.FormValue("stream")
|
||||
if streamName == "" {
|
||||
|
|
@ -219,7 +224,7 @@ func (server Server) streamRecordings(w http.ResponseWriter, r *http.Request) {
|
|||
foundMoment := false
|
||||
|
||||
for i := range images {
|
||||
if i == 0 {
|
||||
if i == 0 { // Skip first for images[i-1] after this if
|
||||
continue
|
||||
}
|
||||
previousImage := images[i-1]
|
||||
|
|
@ -238,6 +243,8 @@ func (server Server) streamRecordings(w http.ResponseWriter, r *http.Request) {
|
|||
continue
|
||||
}
|
||||
|
||||
// if the time difference is lower then the Stream.Interval, it means the Stream.MotionInterval
|
||||
// Was used, and motion was therefore detected.
|
||||
timeDifference := currentTime.Sub(previousTime)
|
||||
if timeDifference < (time.Duration(stream.Interval) * time.Millisecond) {
|
||||
foundMoment = true
|
||||
|
|
@ -273,6 +280,7 @@ func (server Server) streamRecordings(w http.ResponseWriter, r *http.Request) {
|
|||
})
|
||||
}
|
||||
|
||||
// main sets up the HTTP server and reconstructs the Streams, if available.
|
||||
func main() {
|
||||
staticFileServer := http.FileServer(http.Dir("./static"))
|
||||
http.Handle("/static/", http.StripPrefix("/static/", staticFileServer))
|
||||
|
|
@ -292,6 +300,7 @@ func main() {
|
|||
continue
|
||||
}
|
||||
|
||||
// UnMarshal the stream.json into a Stream struct and start a goroutine for UpdateInterval
|
||||
streamJSONPath := filepath.Join(GetStreamDirPath(), streamStoreDir.Name(), "stream.json")
|
||||
stream := StreamFromJSON(streamJSONPath)
|
||||
server.Streams[stream.Name] = stream
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue