當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。