|
@@ -2,14 +2,49 @@ package main
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
+ "io"
|
|
|
"net/http"
|
|
|
+ "os"
|
|
|
)
|
|
|
|
|
|
func Index(w http.ResponseWriter, r *http.Request) {
|
|
|
fmt.Fprintf(w, "Hello world")
|
|
|
+
|
|
|
+ fmt.Println("File opening...")
|
|
|
+ file, err := os.Open("main.go")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ os.Exit(1)
|
|
|
+ }
|
|
|
+ defer file.Close()
|
|
|
+
|
|
|
+ data := make([]byte, 64)
|
|
|
+
|
|
|
+ for {
|
|
|
+ n, err := file.Read(data)
|
|
|
+ if err == io.EOF {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ w.Write(data)
|
|
|
+ fmt.Print(string(data[:n]))
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func Update(w http.ResponseWriter, r *http.Request) {
|
|
|
+ fmt.Println(r.URL.Path)
|
|
|
+ fmt.Println(r.Method)
|
|
|
+ fmt.Println(r.Header)
|
|
|
+
|
|
|
+ if r.URL.Path == "/fw.bin" {
|
|
|
+ fmt.Println("Download update file...")
|
|
|
+ http.ServeFile(w, r, `fw.bin`)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
- http.HandleFunc("/", Index)
|
|
|
+ fmt.Println("Starting HTTP server...")
|
|
|
+ // http.HandleFunc("/", Index)
|
|
|
+ http.HandleFunc("/fw.bin", Update)
|
|
|
http.ListenAndServe(":9000", nil)
|
|
|
}
|