我想访问GO web 某个地址然后是下载文件。
例如我访问: http://127.0.0.1/public/image/img1 这个地址,然后下载文件,跟访问这个一样: http://127.0.0.1/public/image.jpg
更多评论
```
package main
import (
"io/ioutil"
"log"
"net/http"
)
func main() {
http.HandleFunc("/public/image/img1", a)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
func a(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "image/jpeg")
b, _ := ioutil.ReadFile("a.png")
w.Write(b)
}
```
#3