main.go 1.2 KB

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