curl: github.com/Kenshin/curl Index | Files

package curl

import "github.com/Kenshin/curl"

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

Website https://github.com/kenshin/curl

Copyright (c) 2014-2016 Kenshin Wang <kenshin@ksria.com>

Index

Package Files

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

Variables

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. http://nodejs.org/dist/v0.10.0/node.exe

Return code

 0: success
-1: status code != 200

Return res, err

For example:

code, res, _ := curl.Get("http:  nodejs.org/dist/")
if code != 0 {
    return
}
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

   Parameter:
	simple download model:
		url  : download url e.g. http://nodejs.org/dist/v0.10.0/node.exe
		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.

   Return:
	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("http://npm.taobao.org/mirrors/node/v0.10.26/node.exe")
	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("http://7x2xql.com1.z0.glb.clouddn.com/visualhunt.json")
	ts2 := ts.New("http://7x2xql.com1.z0.glb.clouddn.com/holiday/02073.jpg")
	ts3 := ts.New("http://7x2xql.com1.z0.glb.clouddn.com/holiday/0207.jpg")
	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{
		ts.New("http://7x2xql.com1.z0.glb.clouddn.com/visualhunt.json"),
		ts.New("http://7x2xql.com1.z0.glb.clouddn.com/holiday/02073.jpg"),
		ts.New("http://7x2xql.com1.z0.glb.clouddn.com/holiday/0207.jpg"),
	}
	dl.AddTask(ts.New("http://npm.taobao.org/mirrors/node/latest/node.exe", "nodeeeeeeeeeeeeeeeeeeeeeeee.exe"))
	dl.AddTask(ts.New("http://npm.taobao.org/mirrors/node/v5.7.0/win-x64/node.exe", "node4.exe"))
	dl.AddTask(ts.New("https://www.google.com/intl/zh-CN/chrome/browser/?standalone=1&extra=devchannel&platform=win64", "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.