diff --git a/index.html b/index.html new file mode 100755 index 0000000..c988878 --- /dev/null +++ b/index.html @@ -0,0 +1,7 @@ + +

Stream URL

+
+ + +
+ \ No newline at end of file diff --git a/main.go b/main.go index 3c226dd..bc3a4e1 100755 --- a/main.go +++ b/main.go @@ -1,16 +1,43 @@ package main import ( - "fmt" "log" "net/http" + "text/template" ) -func root(w http.ResponseWriter, r *http.Request){ - fmt.Fprint(w, "Root site") +// StreamURL Unexported +type StreamURL struct { + URL string +} + +func index(w http.ResponseWriter, r *http.Request) { + indexTemplate, err := template.ParseFiles(("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) + } + streamURL := StreamURL{ + URL: r.FormValue("URL"), + } + streamTemplate, err := template.ParseFiles(("stream.html")) + + if err != nil { + log.Fatal(err) + } + + streamTemplate.Execute(w, streamURL) } func main() { - http.HandleFunc("/", root) + http.HandleFunc("/", index) + http.HandleFunc("/stream", stream) log.Fatal(http.ListenAndServe(":8080", nil)) -} \ No newline at end of file +} diff --git a/stream.html b/stream.html new file mode 100755 index 0000000..2207758 --- /dev/null +++ b/stream.html @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file