curl: Index | Files

package curl

import ""

Curl - Multiple download lib with CLI by Golang. Vesion 0.0.4


Copyright (c) 2014-2016 Kenshin Wang <>


Package Files

curl.go curl_others.go curl_print.go curl_util.go


var Options = PrintOps{true, true, "[", "]", "=", ">", "_"}

Set PrintOps default values

func Get Uses

func Get(url string) (code int, res *http.Response, err error)

Get URL method

url e.g.

Return code

 0: success
-1: status code != 200

Return res, err

For example:

code, res, _ := curl.Get("http:")
if code != 0 {
defer res.Body.Close()

func ReadLine Uses

func ReadLine(body io.ReadCloser, process processFunc) error

Read line from io.ReadCloser

For example:

versionFunc := func(content string, line int) bool {
     TO DO
  return false

if err := curl.ReadLine(res.Body, versionFunc); err != nil && err != io.EOF {
    TO DO

type CurlError Uses

type CurlError struct {
    // contains filtered or unexported fields

func (CurlError) Error Uses

func (this CurlError) Error() string

defined error interace, Print Error

type Download Uses

type Download []Task

func New Uses

func New(args ...interface{}) (dl Download, errStack []CurlError)
   Download method

	simple download model:
		url  : download url e.g.
		title: download task label.
		name : download file name e.g. node.exe
		dst  : download path
	multi download model:
	Download struct

   Return code:
	 0: success
	-2: create file error.
	-3: download node.exe size error.
	-4: content length = -1.
	-5: panic error.
	-6: curl.New() parameter type error.
	-7: Download size error.
	-8: Write Content-Type:text error.

	dl( []Task Download struct )
	err( []CurlError array)

   Console show:
	Start download [aaa, bbb, node, npm, ccccccc].
		aaa: 70% [==============>__________________] 925ms
		bbb: 10% [===>_____________________________] 2s
	   node: 100% [===============================>] 10s
		npm: download error.
	cccc...: 30% [=========>________________________] 2s
	End download.

   For example:

	// simple download
	newDL, err := New("")
	fmt.Printf("curl.New return ld  is %v\n", newDL)
	fmt.Printf("curl.New return err is %v\n", err)

	// multi download
	ts := Task{}
	ts1 := ts.New("")
	ts2 := ts.New("")
	ts3 := ts.New("")
	newDL, err = New(ts1, ts2, ts3)
	fmt.Printf("curl.New return ld  is %v\n", newDL)
	fmt.Printf("curl.New return err is %v\n", err)

	dl := Download{
	dl.AddTask(ts.New("", "nodeeeeeeeeeeeeeeeeeeeeeeee.exe"))
	dl.AddTask(ts.New("", "node4.exe"))
	dl.AddTask(ts.New("", "Chrome 49"))
	newDL, err = New(dl)

	fmt.Printf("curl.New return ld  is %v\n", newDL)
	fmt.Printf("curl.New return err is %v\n", err)

func (*Download) AddTask Uses

func (this *Download) AddTask(ts Task)

Append task struct to downlaod struct

func (Download) GetValues Uses

func (this Download) GetValues(key string) []string

Return downlaod struct values by key

type PrintOps Uses

type PrintOps struct {
    Header   bool
    Footer   bool
    LeftEnd  string
    RightEnd string
    Fill     string
    Arrow    string
    Empty    string

curl.Print Options

type Task Uses

type Task struct {
    Url   string
    Title string
    Name  string
    Dst   string
    Code  int

func (Task) New Uses

func (this Task) New(args ...interface{}) Task

Receive arguments and return an new task struct

Package curl imports 11 packages (graph) and is imported by 3 packages. Updated 2016-07-18. Refresh now. Tools for package owners.