package main
import (
"bytes"
"fmt"
curl "github.com/andelf/go-curl"
)
func main() {
easy := curl.EasyInit()
defer easy.Cleanup()
easy.Setopt(curl.OPT_URL, "https://www.baidu.com/")
buf = new(bytes.Buffer)
// OPTIONAL - make a callback function
fooTest := func (ptr []byte, userdata interface{}) bool {
buf.Write(ptr)
return true
}
easy.Setopt(curl.OPT_WRITEFUNCTION, fooTest)
if err := easy.Perform(); err != nil {
fmt.Printf("ERROR: %v\n", err)
} else {
println("DEBUG: size=>", buf.Len())
println("DEBUG: content=>", buf.String())
}
}
What do you think? Can this helps others?