package main import ( "fmt" "net/http" "io" "os" ) func Upload(w http.ResponseWriter, r *http.Request) { if r.Method == "POST" { file, header, err := r.FormFile("file") if err != nil { fmt.Printf("FromFileErr") http.Redirect(w, r, "/", http.StatusMovedPermanently) return } outPath := fmt.Sprintf("files/%s", header.Filename) fmt.Printf("upload: %s\n", outPath) outFile, err := os.Create(outPath) if err != nil { panic(err) } defer outFile.Close() io.Copy(outFile, file) outFile.Sync() } http.Redirect(w, r, "/", http.StatusMovedPermanently) } func Index(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, `