当前位置: 首页>>代码示例>>Golang>>正文


Golang go-curl.EasyInit函数代码示例

本文整理汇总了Golang中github.com/andelf/go-curl.EasyInit函数的典型用法代码示例。如果您正苦于以下问题:Golang EasyInit函数的具体用法?Golang EasyInit怎么用?Golang EasyInit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了EasyInit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {

	ch1 := curl.EasyInit()
	ch2 := curl.EasyInit()

	ch1.Setopt(curl.OPT_URL, "http://www.163.com")
	ch1.Setopt(curl.OPT_HEADER, 0)
	ch1.Setopt(curl.OPT_VERBOSE, true)
	ch2.Setopt(curl.OPT_URL, "http://www.baidu.com")
	ch2.Setopt(curl.OPT_HEADER, 0)
	ch2.Setopt(curl.OPT_VERBOSE, true)

	mh := curl.MultiInit()

	mh.AddHandle(ch1)
	mh.AddHandle(ch2)

	for {
		nRunning, _ := mh.Perform()
		// println("n =", nRunning)
		if nRunning == 0 {
			println("ok")
			break
		}
		time.Sleep(1000)
	}

}
开发者ID:ym,项目名称:go-curl,代码行数:28,代码来源:multi_sample.go

示例2: main

func main() {
	var (
		rset, wset, eset            syscall.FdSet
		still_running, curl_timeout int = 0, 0
		err                         error
	)

	ch1 := curl.EasyInit()
	ch2 := curl.EasyInit()

	ch1.Setopt(curl.OPT_URL, "http://www.163.com")
	ch1.Setopt(curl.OPT_HEADER, 0)
	ch1.Setopt(curl.OPT_VERBOSE, true)
	ch2.Setopt(curl.OPT_URL, "http://www.baidu.com")
	ch2.Setopt(curl.OPT_HEADER, 0)
	ch2.Setopt(curl.OPT_VERBOSE, true)

	mh := curl.MultiInit()

	mh.AddHandle(ch1)
	mh.AddHandle(ch2)

	for {
		FD_ZERO(&rset)
		FD_ZERO(&wset)
		FD_ZERO(&eset)

		timeout := syscall.Timeval{Sec: 1, Usec: 0}
		curl_timeout, err = mh.Timeout()
		if err != nil {
			fmt.Printf("Error multi_timeout: %s\n", err)
		}
		if curl_timeout >= 0 {
			timeout.Sec = int64(curl_timeout / 1000)
			if timeout.Sec > 1 {
				timeout.Sec = 1
			} else {
				timeout.Usec = int64((curl_timeout % 1000)) * 1000
			}
		}

		max_fd, err := mh.Fdset(&rset, &wset, &eset)
		if err != nil {
			fmt.Printf("Error FDSET: %s\n", err)
		}

		_, err = syscall.Select(int(max_fd+1), &rset, &wset, &eset, &timeout)
		if err != nil {
			fmt.Printf("Error select: %s\n", err)
		} else {
			still_running, err = mh.Perform()
			if still_running > 0 {
				fmt.Printf("Still running: %d\n", still_running)
			} else {
				break
			}
		}
	}

}
开发者ID:andelf,项目名称:go-curl,代码行数:60,代码来源:multi_and_select.go

示例3: getAllImageUrl

func getAllImageUrl(url string, ep string) {
	//init eas
	easy := curl.EasyInit()
	defer easy.Cleanup()
	//header
	easy = generateHeader(easy)
	//loop page
	for i := 0; i < 100; i++ {
		fmt.Println("page " + strconv.Itoa(i))
		url := url + strconv.Itoa(i)
		ur := getData(easy, url, ep)
		go downloadFromUrl(ur, ep, strconv.Itoa(i+1))

		ts := strings.Split(ur, "/")
		extn := strings.Split(ts[len(ts)-1], ".")
		if len(extn) == 1 {
			i = 100
		} else {
			if extn[1] == "png" || extn[1] == "jpg" {
				//lnjut
			} else {
				i = 100
			}
		}
	}

}
开发者ID:prima101112,项目名称:onepiece,代码行数:27,代码来源:onepiece.go

示例4: main

func main() {
	curl.GlobalInit(curl.GLOBAL_ALL)

	// init the curl session
	easy := curl.EasyInit()
	defer easy.Cleanup()

	// set URL to get
	easy.Setopt(curl.OPT_URL, "http://cn.bing.com/")

	// no progress meter
	easy.Setopt(curl.OPT_NOPROGRESS, true)

	easy.Setopt(curl.OPT_WRITEFUNCTION, write_data)

	// write file
	fp, _ := os.OpenFile(bodyfilename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0777)
	defer fp.Close()
	easy.Setopt(curl.OPT_WRITEDATA, fp)

	// easy.Setopt(curl.OPT_WRITEHEADER, 0)

	if err := easy.Perform(); err != nil {
		println("ERROR: ", err.Error())
	}

}
开发者ID:AterCattus,项目名称:go-curl,代码行数:27,代码来源:sepheaders.go

示例5: getCep

func getCep(id string) string {
	cached := getFromCache(id)
	if cached != "" {
		return cached
	}
	easy := curl.EasyInit()
	defer easy.Cleanup()

	easy.Setopt(curl.OPT_URL, "http://viacep.com.br/ws/"+id+"/json/")

	result := " "

	// make a callback function
	fooTest := func(buf []byte, userdata interface{}) bool {
		result = string(buf)

		return true
	}

	easy.Setopt(curl.OPT_WRITEFUNCTION, fooTest)

	if err := easy.Perform(); err != nil {
		fmt.Printf("ERROR: %v\n", err)
	}

	return saveOnCache(id, result)
}
开发者ID:eminetto,项目名称:goCep,代码行数:27,代码来源:server.go

示例6: main

func main() {
	curl.GlobalInit(curl.GLOBAL_ALL)

	// init the curl session
	easy := curl.EasyInit()
	defer easy.Cleanup()

	easy.Setopt(curl.OPT_URL, "http://cn.bing.com/")

	easy.Setopt(curl.OPT_WRITEFUNCTION, write_data)

	// make a chan
	ch := make(chan string, 100)
	go func(ch chan string) {
		for {
			data := <-ch
			println("Got data size=", len(data))
		}
	}(ch)

	easy.Setopt(curl.OPT_WRITEDATA, ch)

	if err := easy.Perform(); err != nil {
		println("ERROR: ", err.Error())
	}

	time.Sleep(10000) // wait gorotine
}
开发者ID:jmatrix,项目名称:go-curl,代码行数:28,代码来源:channal_callback.go

示例7: test_login

func test_login() {
	easy := curl.EasyInit()
	defer easy.Cleanup()

	fmt.Println(*url)
	easy.Setopt(curl.OPT_URL, *url)

	easy.Setopt(curl.OPT_WRITEFUNCTION, callback)

	var mylogin sLogin
	mylogin.Cmd = 1
	mylogin.User_name = "test1"
	mylogin.Passwd = "passwd"
	mylogin.Ver = 1

	body, err := json.Marshal(mylogin)
	if err != nil {
		panic(err.Error())
	}

	easy.Setopt(curl.OPT_POSTFIELDS, string(body))

	if err := easy.Perform(); err != nil {
		fmt.Printf("ERROR: %v\n", err)
	}
}
开发者ID:bonly,项目名称:exercise,代码行数:26,代码来源:20110731_src_client.go

示例8: main

func main() {
	curl.GlobalInit(curl.GLOBAL_DEFAULT)
	defer curl.GlobalCleanup()
	easy := curl.EasyInit()
	defer easy.Cleanup()

	easy.Setopt(curl.OPT_URL, "ftp://ftp.gnu.org/README")

	// define our callback use lambda function
	easy.Setopt(curl.OPT_WRITEFUNCTION, func(ptr []byte, userdata interface{}) bool {
		file := userdata.(*os.File)
		if _, err := file.Write(ptr); err != nil {
			return false
		}
		return true
	})

	fp, _ := os.OpenFile(filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0777)
	defer fp.Close() // defer close

	easy.Setopt(curl.OPT_WRITEDATA, fp)

	easy.Setopt(curl.OPT_VERBOSE, true)

	if err := easy.Perform(); err != nil {
		println("ERROR", err.Error())
	}
}
开发者ID:AterCattus,项目名称:go-curl,代码行数:28,代码来源:ftpget.go

示例9: test_get_realm

func test_get_realm() {
	//curl -d '{"cmd":3, "machine":1000, "ver":1, "acc_id":1001}' "http://127.0.0.1:9001"
	easy := curl.EasyInit()
	defer easy.Cleanup()

	fmt.Println(*url)
	easy.Setopt(curl.OPT_URL, *url)

	easy.Setopt(curl.OPT_WRITEFUNCTION, callback)
	var getRealm sGet_realm
	getRealm.Cmd = 3
	getRealm.Machine = 1000
	getRealm.Ver = 1
	getRealm.Acc_id = 1001

	body, err := json.Marshal(getRealm)
	if err != nil {
		panic(err.Error())
	}
	easy.Setopt(curl.OPT_POSTFIELDS, string(body))

	if err := easy.Perform(); err != nil {
		fmt.Printf("ERROR: %v\n", err)
	}
}
开发者ID:bonly,项目名称:exercise,代码行数:25,代码来源:20110820_srv_client.go

示例10: main

func main() {
	curl.GlobalInit(curl.GLOBAL_ALL)

	// init the curl session
	easy := curl.EasyInit()
	defer easy.Cleanup()

	easy.Setopt(curl.OPT_URL, "http://curl.haxx.se/download/curl-7.22.0.tar.gz")

	easy.Setopt(curl.OPT_WRITEFUNCTION, write_data)

	easy.Setopt(curl.OPT_NOPROGRESS, false)

	started := int64(0)
	easy.Setopt(curl.OPT_PROGRESSFUNCTION, func(dltotal, dlnow, ultotal, ulnow float64, userdata interface{}) bool {
		// canceled when 50% finished
		if dlnow/dltotal > 0.5 {
			println("")
			// abort downloading
			return false
		}
		if started == 0 {
			started = time.Now().Unix()
		}
		fmt.Printf("Downloaded: %3.2f%%, Speed: %.1fKiB/s \r", dlnow/dltotal*100, dlnow/1000/float64((time.Now().Unix()-started)))
		return true
	})

	if err := easy.Perform(); err != nil {
		fmt.Printf("ERROR: %v\n", err)
	}
}
开发者ID:AterCattus,项目名称:go-curl,代码行数:32,代码来源:progress.go

示例11: test_login

func test_login() {
	easy := curl.EasyInit()
	defer easy.Cleanup()

	fmt.Println(*url)
	easy.Setopt(curl.OPT_URL, *url)

	easy.Setopt(curl.OPT_WRITEFUNCTION, callback)
	easy.Setopt(curl.OPT_POSTFIELDS, "{\"cmd\":1, \"acc_id\":\"[email protected]\", \"passwd\": \"mypasswd\"}")

	if err := easy.Perform(); err != nil {
		fmt.Printf("ERROR: %v\n", err)
	}
}
开发者ID:bonly,项目名称:exercise,代码行数:14,代码来源:20110715_srv_client.go

示例12: test_get_user_id

func test_get_user_id() {
	easy := curl.EasyInit()
	defer easy.Cleanup()

	fmt.Println(*url)
	easy.Setopt(curl.OPT_URL, *url)

	easy.Setopt(curl.OPT_WRITEFUNCTION, callback)
	easy.Setopt(curl.OPT_POSTFIELDS, "{\"cmd\": 5, \"realm_id\":0, \"acc_id\": 1}")

	if err := easy.Perform(); err != nil {
		fmt.Printf("ERROR: %v\n", err)
	}
}
开发者ID:bonly,项目名称:exercise,代码行数:14,代码来源:20110731_src_client.go

示例13: test_get_realm

func test_get_realm() {
	easy := curl.EasyInit()
	defer easy.Cleanup()

	fmt.Println(*url)
	easy.Setopt(curl.OPT_URL, *url)

	easy.Setopt(curl.OPT_WRITEFUNCTION, callback)
	easy.Setopt(curl.OPT_POSTFIELDS, "{\"cmd\":3, \"machine\": 1000, \"ver\": 1}")

	if err := easy.Perform(); err != nil {
		fmt.Printf("ERROR: %v\n", err)
	}
}
开发者ID:bonly,项目名称:exercise,代码行数:14,代码来源:20110715_srv_client.go

示例14: test_login

func test_login() {
	easy := curl.EasyInit()
	defer easy.Cleanup()

	fmt.Println(*url)
	easy.Setopt(curl.OPT_URL, *url)

	easy.Setopt(curl.OPT_WRITEFUNCTION, callback)
	easy.Setopt(curl.OPT_POSTFIELDS, "{\"cmd\":1, \"user_name\":\"test1\", \"passwd\": \"passwd\", \"ver\":1}")

	if err := easy.Perform(); err != nil {
		fmt.Printf("ERROR: %v\n", err)
	}
}
开发者ID:bonly,项目名称:exercise,代码行数:14,代码来源:20110730_src_client.go

示例15: main

func main() {
	url := fmt.Sprintf("http://dev.markitondemand.com/MODApis/Api/v2/Quote/jsonp?symbol=%v&callback=my", os.Args[1])
	easy := curl.EasyInit()
	defer easy.Cleanup()
	easy.Setopt(curl.OPT_URL, url)

	handleData := func(buf []byte, userdata interface{}) bool {
		s := string(buf)
		print(s)
		return true
	}

	easy.Setopt(curl.OPT_WRITEFUNCTION, handleData)
	easy.Perform()
}
开发者ID:franzejr,项目名称:go-stock-market,代码行数:15,代码来源:main.go


注:本文中的github.com/andelf/go-curl.EasyInit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。