veeery basic thing working

This commit is contained in:
BroodjeAap 2020-06-29 18:34:35 +00:00
parent f22d11b123
commit 2cacfcbd56
3 changed files with 48 additions and 5 deletions

7
index.html Executable file
View file

@ -0,0 +1,7 @@
<html>
<h1>Stream URL</h1>
<form action="/stream" method="GET">
<label>URL:</label>
<input type="text" name="URL" size="100">
</form>
</html>

37
main.go
View file

@ -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))
}
}

9
stream.html Executable file
View file

@ -0,0 +1,9 @@
<html>
<head>
</head>
<body>
<img src="{{.URL}}">
</body>
</html>