-
Notifications
You must be signed in to change notification settings - Fork 130
/
sepheaders.go
49 lines (37 loc) · 961 Bytes
/
sepheaders.go
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
package main
import (
curl "github.com/andelf/go-curl"
"os"
)
const (
headerfilename = "head.out"
bodyfilename = "body.out"
)
func write_data(ptr []byte, userdata interface{}) bool {
//println("DEBUG(write_data): ", userdata)
//println("DEBUG", userdata.(interface{}))
fp := userdata.(*os.File)
if _, err := fp.Write(ptr); err == nil {
return true
}
return false
}
func main() {
curl.GlobalInit(curl.GLOBAL_ALL)
// init the curl session
easy := curl.EasyInit()
defer easy.Cleanup()
// set URL to get
easy.Setopt(curl.OPT_URL, "http://cn.bing.com/")
// no progress meter
easy.Setopt(curl.OPT_NOPROGRESS, true)
easy.Setopt(curl.OPT_WRITEFUNCTION, write_data)
// write file
fp, _ := os.OpenFile(bodyfilename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0777)
defer fp.Close()
easy.Setopt(curl.OPT_WRITEDATA, fp)
// easy.Setopt(curl.OPT_WRITEHEADER, 0)
if err := easy.Perform(); err != nil {
println("ERROR: ", err.Error())
}
}