main.go 917 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. )
  6. func Index(w http.ResponseWriter, r *http.Request) {
  7. fmt.Println("Recv data")
  8. /*
  9. fmt.Fprintf(w, "Hello world")
  10. fmt.Println("File opening...")
  11. file, err := os.Open("main.go")
  12. if err != nil {
  13. fmt.Println(err)
  14. os.Exit(1)
  15. }
  16. defer file.Close()
  17. data := make([]byte, 64)
  18. for {
  19. n, err := file.Read(data)
  20. if err == io.EOF {
  21. break
  22. }
  23. w.Write(data)
  24. fmt.Print(string(data[:n]))
  25. }
  26. */
  27. }
  28. func Update(w http.ResponseWriter, r *http.Request) {
  29. fmt.Println(r.URL.Path)
  30. fmt.Println(r.Method)
  31. fmt.Println(r.Header)
  32. if r.URL.Path == "/fw.bin" {
  33. fmt.Println("Download update file...")
  34. http.ServeFile(w, r, `fw.bin`)
  35. }
  36. }
  37. func main() {
  38. fmt.Println("Starting HTTP server...")
  39. http.HandleFunc("/index.html", Index)
  40. http.HandleFunc("/fw.bin", Update)
  41. http.ListenAndServe(":9000", nil)
  42. }