43 lines
820 B
Go
Executable file
43 lines
820 B
Go
Executable file
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"text/template"
|
|
)
|
|
|
|
// 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("/", index)
|
|
http.HandleFunc("/stream", stream)
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
}
|