w1100n
This site is best viewed in Google Chrome
9/27/2019 22:23

https://studygolang.com/articles/11204

package main

import (
    "github.com/gorilla/handlers"
    "log"
    "net/http"
    "os"
    "time"
)

func ServeHTTP(w http.ResponseWriter, r *http.Request) {
    video, err := os.Open("/tmp/foo.mp4")
    if err != nil {
        log.Fatal(err)
    }
    defer video.Close()

    http.ServeContent(w, r, "foo.mp4", time.Now(), video)
}

func main() {
    http.HandleFunc("/", ServeHTTP)
    _ = http.ListenAndServe(":8089", handlers.LoggingHandler(os.Stdout, http.DefaultServeMux))
}

<< Previous Posts Newer Posts >>
辽ICP备14012896