Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Created January 20, 2020 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziadoz/238e3a2881f37e75e6901824f3321d33 to your computer and use it in GitHub Desktop.
Save ziadoz/238e3a2881f37e75e6901824f3321d33 to your computer and use it in GitHub Desktop.
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