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


Golang grequests.Get函数代码示例

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


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

示例1: main

func main() {
	cert, err := tls.LoadX509KeyPair("../cert.pem", "../key.pem")
	if err != nil {
		log.Fatalln("Unable to load cert", err)
	}

	clientCACert, err := ioutil.ReadFile("../cert.pem")
	if err != nil {
		log.Fatal("Unable to open cert", err)
	}

	clientCertPool := x509.NewCertPool()
	clientCertPool.AppendCertsFromPEM(clientCACert)

	tlsConfig := &tls.Config{
		Certificates: []tls.Certificate{cert},
		RootCAs:      clientCertPool,
	}

	tlsConfig.BuildNameToCertificate()
	ro := &grequests.RequestOptions{
		HTTPClient: &http.Client{
			Transport: &http.Transport{TLSClientConfig: tlsConfig},
		},
	}
	resp, err := grequests.Get("https://localhost:8080", ro)
	if err != nil {
		log.Println("Unable to speak to our server", err)
	}

	log.Println(resp.String())
}
开发者ID:f47h3r,项目名称:go-mutual-tls,代码行数:32,代码来源:client.go

示例2: ListServerApp

func ListServerApp() {
	if !Ping() {
		Login()
	}

	var ro = &grequests.RequestOptions{
		Headers: map[string]string{"Cookie": cookie},
	}

	rsp, err := grequests.Get(hubHost+"/api/holes/", ro)
	if err != nil {
		log.Fatal(err)
	}
	defer rsp.Close()

	if !rsp.Ok {
		log.Fatalf("Error: %s\n", rsp.String())
	}

	var holeApps map[string][]HoleApp

	err = rsp.JSON(&holeApps)

	fmt.Println("ID\t\t\t\t\tName\t\tPort\t\t\t\t\tStatus")
	var holeApp, rh HoleApp
	for _, rh = range holeApps["holes"] {
		holeApp, err = NewHoleApp(rh.ID)
		if err != nil {
			holeApp = rh
		}
		fmt.Printf("%s\t%s\t\t%s:%s/%s->%s:%s/%s\t%s\n", holeApp.ID,
			holeApp.Name, holeApp.Lhost, holeApp.Lport, holeApp.Lscheme, holeApp.Host, holeApp.Port, holeApp.Scheme, holeApp.Status)
	}
}
开发者ID:ultimate010,项目名称:holehub,代码行数:34,代码来源:holehub.go

示例3: Example_cookies

func Example_cookies() {
	resp, err := grequests.Get("http://httpbin.org/cookies",
		&grequests.RequestOptions{
			Cookies: []http.Cookie{
				{
					Name:     "TestCookie",
					Value:    "Random Value",
					HttpOnly: true,
					Secure:   false,
				}, {
					Name:     "AnotherCookie",
					Value:    "Some Value",
					HttpOnly: true,
					Secure:   false,
				},
			},
		})

	if err != nil {
		log.Println("Unable to make request", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

	log.Println(resp.String())
}
开发者ID:wambiri,项目名称:grequests,代码行数:28,代码来源:example_test.go

示例4: Setup

// Setup download selected version to target dir and unpacks it
func (v *Version) Setup(rootDir string) error {
	sdkRoot := filepath.Join(rootDir, v.Release)
	os.MkdirAll(sdkRoot, 0755)
	targetFile := filepath.Join(rootDir, v.name)

	if _, err := os.Stat(targetFile); os.IsNotExist(err) {
		resp, err := req.Get(
			v.remoteURL,
			&req.RequestOptions{
				UserAgent: "Mozilla/5.0 (compatible; Gobu; +https://github.com/dz0ny/gobu)",
			},
		)
		if err != nil {
			return err
		}

		log.Infoln("Starting download of ", v.String())
		err = resp.DownloadToFile(targetFile)
		if err != nil {
			return err
		}
		log.Infoln("Starting extraction of ", targetFile)
		if strings.HasSuffix(v.name, ".zip") {
			return archive.Unzip(targetFile, sdkRoot)
		}
		if strings.HasSuffix(v.name, ".tar.gz") {
			return archive.Untar(targetFile, sdkRoot)
		}
		return errors.New("Unsuported archive type")

	}
	return nil
}
开发者ID:dz0ny,项目名称:gobu,代码行数:34,代码来源:version.go

示例5: Gather

func (p Ping) Gather(self serf.Member, e serf.Event) error {
	// TODO check http response
	p.logger.Info("inspecting HTTP endpoint: %s", p.Endpoint)
	resp, err := grequests.Get(p.Endpoint, nil)
	if err != nil || !resp.Ok {
		p.logger.Error("failed to ping endpoint: %s", err)
		return p.notify(err)
	}

	return nil
}
开发者ID:hackliff,项目名称:sentinel,代码行数:11,代码来源:ping.go

示例6: Example_acceptInvalidTLSCert

func Example_acceptInvalidTLSCert() {
	ro := &grequests.RequestOptions{InsecureSkipVerify: true}
	resp, err := grequests.Get("https://www.pcwebshop.co.uk/", ro)

	if err != nil {
		log.Println("Unable to make request", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}
}
开发者ID:wambiri,项目名称:grequests,代码行数:12,代码来源:example_test.go

示例7: Example_basicAuth

func Example_basicAuth() {
	ro := &grequests.RequestOptions{Auth: []string{"Levi", "Bot"}}
	resp, err := grequests.Get("http://httpbin.org/get", ro)
	// Not the usual JSON so copy and paste from below

	if err != nil {
		log.Println("Unable to make request", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}
}
开发者ID:wambiri,项目名称:grequests,代码行数:13,代码来源:example_test.go

示例8: Example_customUserAgent

func Example_customUserAgent() {
	ro := &grequests.RequestOptions{UserAgent: "LeviBot 0.1"}
	resp, err := grequests.Get("http://httpbin.org/get", ro)

	if err != nil {
		log.Fatal("Oops something went wrong: ", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

	log.Println(resp.String())
}
开发者ID:wambiri,项目名称:grequests,代码行数:14,代码来源:example_test.go

示例9: Example_customHTTPHeader

func Example_customHTTPHeader() {
	ro := &grequests.RequestOptions{UserAgent: "LeviBot 0.1",
		Headers: map[string]string{"X-Wonderful-Header": "1"}}
	resp, err := grequests.Get("http://httpbin.org/get", ro)
	// Not the usual JSON so copy and paste from below

	if err != nil {
		log.Println("Unable to make request", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}
}
开发者ID:wambiri,项目名称:grequests,代码行数:14,代码来源:example_test.go

示例10: Example_basicGetCustomHTTPClient

func Example_basicGetCustomHTTPClient() {
	// This is a very basic GET request
	resp, err := grequests.Get("http://httpbin.org/get", &grequests.RequestOptions{HTTPClient: http.DefaultClient})

	if err != nil {
		log.Println(err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

	log.Println(resp.String())
}
开发者ID:wambiri,项目名称:grequests,代码行数:14,代码来源:example_test.go

示例11: get

func (client *Client) get(path string, options *grequests.RequestOptions) (*simplejson.Json, error) {
	if options == nil {
		options = client.provider.options()
	}
	resp, err := grequests.Get(client.provider.baseURL()+path, options)
	if err != nil {
		return nil, err
	}
	if !resp.Ok {
		return nil, NewErrorFromBody(resp.String())
	}

	return simplejson.NewFromReader(resp)
}
开发者ID:aisk,项目名称:lean-cli-backup,代码行数:14,代码来源:client.go

示例12: Example_basicGet

func Example_basicGet() {
	// This is a very basic GET request
	resp, err := grequests.Get("http://httpbin.org/get", nil)

	if err != nil {
		log.Println(err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

	log.Println(resp.String())
}
开发者ID:wambiri,项目名称:grequests,代码行数:14,代码来源:example_test.go

示例13: Example_urlQueryParams

func Example_urlQueryParams() {
	ro := &grequests.RequestOptions{
		Params: map[string]string{"Hello": "World", "Goodbye": "World"},
	}
	resp, err := grequests.Get("http://httpbin.org/get", ro)
	// url will now be http://httpbin.org/get?hello=world&goodbye=world

	if err != nil {
		log.Println("Unable to make request", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}
}
开发者ID:wambiri,项目名称:grequests,代码行数:15,代码来源:example_test.go

示例14: FetchRepo

// FetchRepo will download the boilerplate from remote and extract to ${appName}/ folder
func FetchRepo(t int, appName string, appID string) error {
	utils.CheckError(os.Mkdir(appName, 0700))

	repoURL := map[int]string{
		Python: "http://lcinternal-cloud-code-update.leanapp.cn/python-getting-started.zip",
		NodeJS: "http://lcinternal-cloud-code-update.leanapp.cn/node-js-getting-started.zip",
	}[t]

	dir, err := ioutil.TempDir("", "leanengine")
	utils.CheckError(err)
	defer os.RemoveAll(dir)

	log.Println("正在下载项目模版...")

	resp, err := grequests.Get(repoURL, nil)
	if err != nil {
		return err
	}
	defer resp.Close()
	if resp.StatusCode != 200 {
		return errors.New(utils.FormatServerErrorResult(resp.String()))
	}

	log.Println("下载完成")

	zipFilePath := filepath.Join(dir, "getting-started.zip")
	resp.DownloadToFile(zipFilePath)

	log.Println("正在创建项目...")

	zipFile, err := zip.OpenReader(zipFilePath)
	utils.CheckError(err)
	defer zipFile.Close()
	for _, f := range zipFile.File {
		err := extractAndWriteFile(f, appName)
		if err != nil {
			return err
		}
	}

	if err := apps.AddApp(appName, appName, appID); err != nil {
		return err
	}

	log.Println("创建项目完成")

	return nil
}
开发者ID:aisk,项目名称:lean-cli-backup,代码行数:49,代码来源:boilerplate.go

示例15: main

func main() {
	response, err := grequests.Get("http://127.0.0.1:3000/register", nil)
	if err != nil {
		panic("Unable to register:" + err.Error())
	}
	respdata := strings.Split(response.String(), ",")
	id := respdata[0]
	clienttest := respdata[1]
	worker, err := gowork.NewWorker("w4PYxQjVP9ZStjWpBt5t28CEBmRs8NPx", id, clienttest)
	testresponse, err := grequests.Post("http://127.0.0.1:3000/verify", &grequests.RequestOptions{Params: map[string]string{"id": id, "clientresp": worker.Verification.ClientResponse}})
	if err != nil {
		panic("Unable to verify:" + err.Error())
	}
	worker = worker.SetAuthenticationKey(testresponse.String())
	fmt.Println(worker.SessionAuthenticationKey)
}
开发者ID:zeb209,项目名称:GoWork,代码行数:16,代码来源:main.go


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