Skip to content

Instantly share code, notes, and snippets.

Created July 7, 2020 03:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Transfer-Encoding: chunked
package main
import (
func main() {
http.HandleFunc("/videos/big-buck-bunny.mp4", func(w http.ResponseWriter, r *http.Request) {
// Direct file serving
//http.ServeFile(w, r, "videos/big-buck-bunny.mp4")
w.Header().Set("Content-Type", "video/mp4")
w.Header().Set("Transfer-Encoding", "chunked")
f, _ := os.Open("videos/big-buck-bunny.mp4")
// Using a Reader?
//r := bufio.NewReader(f)
// Using Buffer
//streamVideoBytes, _ := ioutil.ReadFile("videos/big-buck-bunny.mp4")
//b := bytes.NewBuffer(streamVideoBytes)
// Using a Copy
io.Copy(w, f)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, `<!DOCTYPE html>
<video controls autoplay width="1024">
<source src="/videos/big-buck-bunny.mp4" type="video/mp4">
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Print("Hello from Cloud Run! The container started successfully and is listening for HTTP requests on $PORT.")
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment