Created
January 20, 2020 20:50
-
-
Save ziadoz/238e3a2881f37e75e6901824f3321d33 to your computer and use it in GitHub Desktop.
Go Video Web NAS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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