|
- package main
-
- import (
- "io"
- "io/ioutil"
- "log"
- "net/http"
- "os"
- "time"
- )
-
- func saveURL(url string) (tmpFile string, contentType string, err error) {
- var myClient = &http.Client{Timeout: 20 * time.Second}
- r, err := myClient.Get(url)
- if err != nil {
- log.Fatal("Fail to get URL:" + url)
- log.Fatal(err)
- return "", "", err
- }
- defer r.Body.Close()
- file, err := ioutil.TempFile(os.TempDir(), "wechat_hitxy_")
- // Use io.Copy to just dump the response body to the file. This supports huge files
- _, err = io.Copy(file, r.Body)
- if err != nil {
- log.Fatal(err)
- }
- tmpFile = file.Name()
- file.Close()
- return
- }
|