From bf1b784758dfcbca55296fe4ef6af6360dadd71f Mon Sep 17 00:00:00 2001 From: Scott Prive Date: Sat, 6 Jul 2024 00:53:26 -0400 Subject: [PATCH 1/6] Update README --- README.md | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a299335..492c6e3 100644 --- a/README.md +++ b/README.md @@ -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 ------- @@ -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 @@ -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)) @@ -71,3 +84,5 @@ func main() { } } ``` + +See also the [examples](./examples/) directory! From c390def4c6512f9b80cf1605e99b17b483f7239a Mon Sep 17 00:00:00 2001 From: Scott Prive Date: Sat, 6 Jul 2024 00:55:23 -0400 Subject: [PATCH 2/6] Move the unsafe verifypeer disable to own example --- examples/https.go | 5 +---- examples/https_skip_peer_verify.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 examples/https_skip_peer_verify.go diff --git a/examples/https.go b/examples/https.go index 0a4e031..a305c30 100644 --- a/examples/https.go +++ b/examples/https.go @@ -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() } } diff --git a/examples/https_skip_peer_verify.go b/examples/https_skip_peer_verify.go new file mode 100644 index 0000000..d0aafdc --- /dev/null +++ b/examples/https_skip_peer_verify.go @@ -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() + } +} From 0504544176a8c9ac55476e6693d5e1683a8ab08b Mon Sep 17 00:00:00 2001 From: Scott Prive Date: Sat, 6 Jul 2024 00:56:56 -0400 Subject: [PATCH 3/6] extend example HTTP UA to have repo ORL --- examples/misc.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/misc.go b/examples/misc.go index d66d2b7..dd054c3 100644 --- a/examples/misc.go +++ b/examples/misc.go @@ -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" @@ -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 From 623bc9d4c0a85cd5b7f45a8019c350e02cc15aeb Mon Sep 17 00:00:00 2001 From: Scott Prive Date: Sat, 6 Jul 2024 00:57:36 -0400 Subject: [PATCH 4/6] Put the README's example into own example file --- examples/https_callback.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/https_callback.go diff --git a/examples/https_callback.go b/examples/https_callback.go new file mode 100644 index 0000000..5de5255 --- /dev/null +++ b/examples/https_callback.go @@ -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) + } +} From 24f0726e71e03f6607ed9575426907045bb200fe Mon Sep 17 00:00:00 2001 From: Scott Prive Date: Sat, 6 Jul 2024 00:58:15 -0400 Subject: [PATCH 5/6] add basic go.mod --- go.mod | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..004a461 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/andelf/go-curl + +go 1.21.5 From cce098b3a6aff5b3a647d9b6ce69536f9412b45d Mon Sep 17 00:00:00 2001 From: Scott Prive Date: Sat, 6 Jul 2024 01:12:23 -0400 Subject: [PATCH 6/6] just Python --- misc/codegen.py | 2 +- misc/compatgen.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/misc/codegen.py b/misc/codegen.py index 050f826..7ee8310 100644 --- a/misc/codegen.py +++ b/misc/codegen.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # -*- coding: utf-8 -*- import os diff --git a/misc/compatgen.py b/misc/compatgen.py index 2646d4d..cb41359 100644 --- a/misc/compatgen.py +++ b/misc/compatgen.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # -*- coding: utf-8 -*- import os @@ -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))