LoginSignup
2
2

More than 5 years have passed since last update.

HTTPでzipを返すメモ

Posted at

簡単なダウンローダのような物を作ろうとしてすんなり調べて出て来なかったのでそのメモ

package main

import (
    "io/ioutil"
    "net/http"
)


func zipDownload(w http.ResponseWriter, r *http.Request) {
    file, err := ioutil.ReadFile("test.zip")
    if err != nil {
        fmt.Println(err)
        return
    }
    w.Header().Set("Content-Type", "application/zip")
    w.WriteHeader(http.StatusOK)
    w.Write(file)

}


func main() {
    http.HandleFunc("/", zipDownload)
    http.ListenAndServe(":8080", nil)
}

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2