Created
August 21, 2010 22:18
-
-
Save mrosset/542939 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gurl | |
/* | |
#include <curl/curl.h> | |
#include <curl/types.h> | |
#include <curl/easy.h> | |
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { | |
size_t written = fwrite(ptr, size, nmemb, stream); | |
return written; | |
} | |
void download(char* url, char* dest) { | |
CURL *curl; | |
FILE *fp; | |
CURLcode res; | |
curl = curl_easy_init(); | |
if(curl) { | |
fp = fopen(dest,"wb"); | |
curl_easy_setopt(curl, CURLOPT_URL, url); | |
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); | |
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); | |
res = curl_easy_perform(curl); | |
curl_easy_cleanup(curl); | |
fclose(fp); | |
} | |
} | |
*/ | |
import "C" | |
import "path" | |
func Download(url string) { | |
_, file := path.Split(url) | |
C.download(C.CString(url), C.CString(file)) | |
println(url) | |
} | |
func Version() string { | |
version := C.GoString(C.curl_version()) | |
return version | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment