Skip to content

Instantly share code, notes, and snippets.

@ziadoz ziadoz/main.go
Created Jan 20, 2020

Embed
What would you like to do?
Go Video Web NAS
// Create a video with the path: ./media/test.mkv
package main
import (
"log"
"net/http"
"text/template"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/media/", func(w http.ResponseWriter, r *http.Request) {
h := http.StripPrefix("/media/", http.FileServer(http.Dir("./media")))
h.ServeHTTP(w, r)
})
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-type", "text/html")
t := template.Must(template.New("index").Parse(`<video src="/media/test.mkv" type="video/mkv" controls style="width: 100%; height: 100%"></video>`))
t.ExecuteTemplate(w, "index", map[string]string{})
})
log.Fatal(http.ListenAndServe(":8000", mux))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.