-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (45 loc) · 966 Bytes
/
main.go
File metadata and controls
51 lines (45 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"database/sql"
"errors"
"fmt"
"io"
"net/http"
"os"
"strconv"
"time"
)
func Download(w http.ResponseWriter, r *http.Request) {
filename := "/Users/guochenglong/Downloads/sqweqweqeq.zip"
file, _ := os.OpenFile(filename, os.O_CREATE, 0777)
defer file.Close()
fileStat, _ := file.Stat()
resp, err := http.Get("https://baidu.com")
w.Header().Set("Content-Disposition", "attachment; filename=ww22w.zip")
w.Header().Set("Content-Length", strconv.FormatInt(fileStat.Size(), 10))
file.Seek(0, 0)
_, err = io.Copy(file, resp.Body)
_, err = io.Copy(w, file)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
_, _ = io.WriteString(w, "Bad request")
return
}
fmt.Println(333333333)
}
type Data struct {
t sql.NullTime
t1 time.Time
t2 *time.Time
}
func main() {
defer func() {
var err error
fmt.Println("defer", err)
}()
err := demo()
fmt.Println("demo", err)
}
func demo() error {
return errors.New("aaa")
}