func FindVideo() http.HandlerFunc { return func(response http.ResponseWriter, request *http.Request) { params := mux.Vars(request) id := params["id"] _, err := models.Get(id) if err != nil { log.Println(err) } cmd := exec.Command("../find_video.sh", "-i", id, "-e", settings.Env) err = cmd.Start() if err != nil { log.Println(err) } log.Println("Waiting for command", "./find_video.sh", "-i", id, "-e", settings.Env, "to finish...") err = cmd.Wait() if err != nil { log.Printf("Command %v %v %v %v finished with error: %v", "./find_video.sh -i", id, "-e", settings.Env, err) } else { log.Println("Command", "./find_video.sh", "-i", id, "-e", settings.Env, "finished without any errors") } response.Header().Set("Content-Type", "application/json") jsonStr := `{"app": {"notice": {"text": "The task will be processed"}}}` response.Write([]byte(jsonStr)) } }
func InnerPage() http.HandlerFunc { path, err := filepath.Abs("./templates/inner.html") if err != nil { log.Fatal(err) } not_found_path, err := filepath.Abs("./templates/404.html") if err != nil { log.Fatal(err) } funcMap := template.FuncMap{ "formattedDate": formattedDate, "embedVideo": embedVideo, "imageUrl": imageUrl, "pageTitle": pageTitle, } tmpl := template.New("inner.html").Funcs(funcMap) tmpl, templateError := tmpl.ParseFiles(path) if templateError != nil { log.Fatal(templateError) } not_found_tmpl, templateError := template.ParseFiles(not_found_path) if templateError != nil { log.Fatal(templateError) } return func(response http.ResponseWriter, request *http.Request) { params := mux.Vars(request) id := params["id"] video, err := models.Get(id) if err != nil { log.Println(err) response.WriteHeader(404) not_found_tmpl.Execute(response, nil) } else { tmpl.Execute(response, video) } } }