diff --git a/main.go b/main.go index 178b21f..d8a7c8a 100755 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "io/ioutil" "log" "net/http" "path/filepath" @@ -13,17 +14,13 @@ type StreamURL struct { } func index(w http.ResponseWriter, r *http.Request) { - indexTemplate, err := template.ParseFiles(filepath.Join("templates", "index.html")) - if err != nil { - log.Fatal(err) - } - indexTemplate.Execute(w, nil) - -} - -func stream(w http.ResponseWriter, r *http.Request) { if r.FormValue("URL") == "" { - http.Redirect(w, r, "/", http.StatusTemporaryRedirect) + indexTemplate, err := template.ParseFiles(filepath.Join("templates", "index.html")) + if err != nil { + log.Fatal(err) + } + indexTemplate.Execute(w, nil) + return } streamURL := StreamURL{ URL: r.FormValue("URL"), @@ -37,6 +34,22 @@ func stream(w http.ResponseWriter, r *http.Request) { streamTemplate.Execute(w, streamURL) } +func stream(w http.ResponseWriter, r *http.Request) { + if r.FormValue("URL") == "" { + return + } + //w.Header().Set("Content-Type", "image/jpeg") + URL := r.FormValue("URL") + resp, err := http.Get(URL) + if err != nil { + log.Fatal(err) + } + img, err := ioutil.ReadAll(resp.Body) + defer resp.Body.Close() + + w.Write([]byte(img)) +} + func main() { staticFileServer := http.FileServer(http.Dir("./static")) http.Handle("/static/", http.StripPrefix("/static/", staticFileServer)) diff --git a/static/css/style.css b/static/css/style.css new file mode 100755 index 0000000..e69de29 diff --git a/static/js/stream.js b/static/js/stream.js index 66d9aec..e69de29 100755 --- a/static/js/stream.js +++ b/static/js/stream.js @@ -1 +0,0 @@ -alert("test"); \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index c988878..71df467 100755 --- a/templates/index.html +++ b/templates/index.html @@ -1,6 +1,6 @@

Stream URL

-
+
diff --git a/templates/stream.html b/templates/stream.html index 345674c..9af9cf5 100755 --- a/templates/stream.html +++ b/templates/stream.html @@ -1,9 +1,10 @@ - + + - + \ No newline at end of file