go-curl is a GoLang interface to libcurl, the multiprotocol file transfer library. Similar to the HTTP support in [net/http] (https://pkg.go.dev/net/http), go-curl can be used to fetch objects from a Go program. While go-curl can provide simple fetches, it also exposes most of the functionality of libcurl, including:
This said, libcurl API can be less easy to learn than net/http.
go-curl is licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html).
$ go get -u github.com/andelf/go-curl
package main
import (
"fmt"
curl "github.com/andelf/go-curl"
)
func main() {
easy := curl.EasyInit()
defer easy.Cleanup()
easy.Setopt(curl.OPT_URL, "https://www.baidu.com/")
// OPTIONAL - make a callback function
fooTest := func (buf []byte, userdata interface{}) bool {
println("DEBUG: size=>", len(buf))
println("DEBUG: content=>", string(buf))
return true
}
easy.Setopt(curl.OPT_WRITEFUNCTION, fooTest)
if err := easy.Perform(); err != nil {
fmt.Printf("ERROR: %v\n", err)
}
}
See also the examples directory!