From 2cacfcbd56a84ed09912640d2e5aab3cd6d286f9 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Mon, 29 Jun 2020 18:34:35 +0000 Subject: [PATCH] veeery basic thing working --- index.html | 7 +++++++ main.go | 37 ++++++++++++++++++++++++++++++++----- stream.html | 9 +++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100755 index.html create mode 100755 stream.html 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