package main
import (
"io/ioutil"
"net/http"
"html/template"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("index.html")
t.Execute(w, nil)
}
func downloadHandler(w http.ResponseWriter, r *http.Request) {
imageURL := "適当な画像URL"
res, _ := http.Get(imageURL)
data, _ := ioutil.ReadAll(res.Body)
defer res.Body.Close()
w.Header().Set("Content-Disposition", "attachment; filename=tmp.png")
w.Header().Set("Content-Type", "image/png")
w.Write(data)
}
func main() {
http.HandleFunc("/", indexHandler)
http.HandleFunc("/download", downloadHandler)
http.ListenAndServe(":8000", nil)
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme