fwriter.go 608 B

123456789101112131415161718192021222324252627282930
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "io"
  6. "net/http"
  7. )
  8. func main() {
  9. fmt.Println("FileWriter web server, post to /api/v1/flv to temp.flv")
  10. http.HandleFunc("/api/v1/flv", func(w http.ResponseWriter, r *http.Request){
  11. defer r.Body.Close()
  12. var f *os.File
  13. var err error
  14. if f,err = os.OpenFile("temp.flv", os.O_RDWR|os.O_APPEND|os.O_CREATE, os.ModePerm); err != nil {
  15. return
  16. }
  17. var written int64
  18. written,err = io.Copy(f, r.Body)
  19. fmt.Println(fmt.Sprintf("write to file temp.flv, %v bytes", written))
  20. if err != nil {
  21. return
  22. }
  23. })
  24. _ = http.ListenAndServe(fmt.Sprintf(":8088"), nil)
  25. }