-
Notifications
You must be signed in to change notification settings - Fork 0
/
html5_video.go
38 lines (32 loc) · 948 Bytes
/
html5_video.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"net/http"
"os"
"log"
"io/ioutil"
)
// <video src="http://127.0.0.1:8000/video" width="520" controls="controls">error</video>
func video(w http.ResponseWriter, r *http.Request) {
path := "go.mp4"
file, err := os.Open(path)
if err != nil {
log.Println(err, "Open")
http.Error(w, "Internal Server Error: " + err.Error(), http.StatusInternalServerError)
return
}
defer file.Close()
fd, err := ioutil.ReadAll(file)
if err != nil {
log.Println(err, "ReadAll")
http.Error(w, "Internal Server Error: " + err.Error(), http.StatusInternalServerError)
return
}
w.Header().Add("Content-Type", "video/mp4")
n, err := w.Write(fd)
if err != nil {
log.Println(err, "Write")
http.Error(w, "Internal Server Error: " + err.Error(), http.StatusInternalServerError)
} else {
log.Println(n, "Ok")
}
}