Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ go-curl

[![Build Status](https://secure.travis-ci.org/andelf/go-curl.png?branch=master)](http://travis-ci.org/andelf/go-curl)

my golang libcurl(curl) binding.
go-curl is a GoLang interface to [libcurl](https://curl.haxx.se/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:

See more examples in ./examples/ directory~!
* Speed - libcurl is very fast.
* Multiple protocol (not just HTTP).
* SSL, authentication and proxy support.
* Support for libcurl's callbacks.

This said, libcurl API can be less easy to learn than net/http.

LICENSE
-------
Expand All @@ -22,11 +31,15 @@ Current Development Status
* partly implement share & multi interface
* new callback function prototype

How to Install
--------------
Requirements
------------
* Any version of Go
* libcurl 7.x or higher (including development headers and static/dynamic libs)
* Python 3 (used only by configure scripts)

Make Sure You Have libcurl (and its develop headers, static/dynamic libs) installed!

How to Install
--------------

$ go get -u github.com/andelf/go-curl

Expand Down Expand Up @@ -55,9 +68,9 @@ func main() {
easy := curl.EasyInit()
defer easy.Cleanup()

easy.Setopt(curl.OPT_URL, "http://www.baidu.com/")
easy.Setopt(curl.OPT_URL, "https://www.baidu.com/")

// make a callback function
// OPTIONAL - make a callback function
fooTest := func (buf []byte, userdata interface{}) bool {
println("DEBUG: size=>", len(buf))
println("DEBUG: content=>", string(buf))
Expand All @@ -71,3 +84,5 @@ func main() {
}
}
```

See also the [examples](./examples/) directory!
5 changes: 1 addition & 4 deletions examples/https.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ func main() {
easy := curl.EasyInit()
defer easy.Cleanup()
if easy != nil {
easy.Setopt(curl.OPT_URL, "https://mail.google.com/")
// skip_peer_verification
easy.Setopt(curl.OPT_SSL_VERIFYPEER, false) // 0 is ok

easy.Setopt(curl.OPT_URL, "https://baidu.com/")
easy.Perform()
}
}
26 changes: 26 additions & 0 deletions examples/https_callback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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)
}
}
20 changes: 20 additions & 0 deletions examples/https_skip_peer_verify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
curl "github.com/andelf/go-curl"
)

func main() {
easy := curl.EasyInit()
defer easy.Cleanup()
if easy != nil {
easy.Setopt(curl.OPT_URL, "https://mail.google.com/")

// OPT_SSL_VERIFYPEER determines whether curl verifies the authenticity of the peer's certificate.
// Do not disable OPT_SSL_VERIFYPEER unless you absolutely sure of the security implications.
// https://curl.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html
easy.Setopt(curl.OPT_SSL_VERIFYPEER, false) // 0 also means false

easy.Perform()
}
}
5 changes: 3 additions & 2 deletions examples/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package main

import (
"fmt"
curl "github.com/andelf/go-curl"
"os"
"reflect"

curl "github.com/andelf/go-curl"
)

const endl = "\n"
Expand Down Expand Up @@ -37,7 +38,7 @@ func main() {
}
//print("set url =>", ret.Setopt(curl.OPT_URL, "http://commondatastorage.googleapis.com/chromium-browser-continuous/Linux_x64/104547/chrome-linux.zip"), endl)

print("set user_agent =>", ret.Setopt(curl.OPT_USERAGENT, "go-curl v0.0.1") == nil, endl)
print("set user_agent =>", ret.Setopt(curl.OPT_USERAGENT, "github.com/andelf/go-curl v0.0.1") == nil, endl)
// add to DNS cache
print("set resolve =>", ret.Setopt(curl.OPT_RESOLVE, []string{"www.baidu.com:8000:127.0.0.1"}) == nil, endl)
// ret.EasyReset() clean seted
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/andelf/go-curl

go 1.21.5
2 changes: 1 addition & 1 deletion misc/codegen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
Expand Down
4 changes: 2 additions & 2 deletions misc/compatgen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
Expand Down Expand Up @@ -118,5 +118,5 @@ def version_symbol(ver):

result.extend(result_tail)

with open("./compat.h", 'w') as fp:
with open("./compat.h", 'w', encoding='utf-8') as fp:
fp.write('\n'.join(result))