當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Session.Get方法代碼示例

本文整理匯總了Golang中github.com/jmcvetta/napping.Session.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Get方法的具體用法?Golang Session.Get怎麽用?Golang Session.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/jmcvetta/napping.Session的用法示例。


在下文中一共展示了Session.Get方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	//
	// Struct to hold error response
	//
	e := struct {
		Message string
	}{}

	// Start Session
	s := napping.Session{}
	url := "http://httpbin.org/user-agent"
	fmt.Println("URL:>", url)

	res := ResponseUserAgent{}
	resp, err := s.Get(url, nil, &res, nil)
	if err != nil {
		log.Fatal(err)
	}
	//
	// Process response
	//
	println("")
	fmt.Println("response Status:", resp.Status())

	if resp.Status() == 200 {
		// fmt.Printf("Result: %s\n\n", resp.response)
		// resp.Unmarshal(&e)
		fmt.Println("res:", res.Useragent)
	} else {
		fmt.Println("Bad response status from Github server")
		fmt.Printf("\t Status:  %v\n", resp.Status())
		fmt.Printf("\t Message: %v\n", e.Message)
	}
	fmt.Println("--------------------------------------------------------------------------------")
	println("")

	url = "http://httpbin.org/get"
	fmt.Println("URL:>", url)
	fooParams := napping.Params{"foo": "bar"}
	p := fooParams

	res = ResponseUserAgent{}
	resp, err = s.Get(url, &p, &res, nil)
	if err != nil {
		log.Fatal(err)
	}
	//
	// Process response
	//
	println("")
	fmt.Println("response Status:", resp.Status())
	fmt.Println("--------------------------------------------------------------------------------")
	fmt.Println("Header")
	fmt.Println(resp.HttpResponse().Header)
	fmt.Println("--------------------------------------------------------------------------------")
	fmt.Println("RawText")
	fmt.Println(resp.RawText())
	println("")
}
開發者ID:Skarlso,項目名稱:slick,代碼行數:59,代碼來源:httpbin.go

示例2: Get

func (u *UserInfo) Get(token oauth2.Token) {
	ns := napping.Session{}
	ns.Header = &http.Header{}
	ns.Header.Add("Authorization", "Bearer "+token.AccessToken)
	url := settings.UnifiedApiEndpointUrl + "/me"
	resp, err := ns.Get(url, nil, &u, nil)
	if err != nil {
		log.Fatal(err)
	}
	if resp.Status() == 200 {
		fmt.Println("Loaded profile for :", u.Displayname)
	} else {
		fmt.Println("Bad response status from office365 unified api")
		fmt.Println("Raw Response Text : %s", resp.RawText())
	}
}
開發者ID:rprakashg,項目名稱:go-o365api-explorer,代碼行數:16,代碼來源:client.go

示例3: getRESTResponse

func getRESTResponse(url string, p *url.Values, result interface{}) {
	//
	// Struct to hold error response
	//
	e := struct {
		Message string
	}{}

	s := napping.Session{}
	resp, err := s.Get(url, p, result, e)
	if err != nil {
		log.Fatal(err)
	}
	Trace.Printf("%s Return Status [%v]", url, resp.Status())
	if resp.Status() == 200 {
		return
	} else {
		log.Fatal("Resource could not be fetched")
		log.Fatal("\t Status:  %v\n", resp.Status())
		log.Fatal("\t Message: %v\n", e.Message)
	}
}
開發者ID:doctori,項目名稱:MoviePicker,代碼行數:22,代碼來源:MoviePicker.go

示例4: SendRequest

func SendRequest(u string, method int, sess *napping.Session, pload interface{}, res interface{}) (error, *napping.Response) {

	//
	// Send request to server
	//
	e := httperr{}
	var (
		err  error
		resp *napping.Response
	)
	sess.Log = debug

	switch method {
	case GET:
		resp, err = sess.Get(u, nil, &res, &e)
	case POST:
		resp, err = sess.Post(u, &pload, &res, &e)
	case PUT:
		resp, err = sess.Put(u, &pload, &res, &e)
	case PATCH:
		resp, err = sess.Patch(u, &pload, &res, &e)
	case DELETE:
		resp, err = sess.Delete(u, &res, &e)
	}

	if err != nil {
		return err, resp
	}
	if resp.Status() == 401 {
		return errors.New("unauthorised - check your username and passwd"), resp
	}
	if resp.Status() >= 300 {
		return errors.New(e.Message), resp
	} else {
		// all is good in the world
		return nil, resp
	}
}
開發者ID:skendall,項目名稱:f5er,代碼行數:38,代碼來源:util.go

示例5: goCrestEMDRBridge

func goCrestEMDRBridge() {

	var err error

	type regionKey struct {
		RegionID int64
		TypeID   int64
	}

	type marketRegions struct {
		RegionID   int64  `db:"regionID"`
		RegionName string `db:"regionName"`
	}

	type marketTypes struct {
		TypeID   int64  `db:"typeID"`
		TypeName string `db:"typeName"`
	}

	// Pool of CREST sessions
	crestSession := napping.Session{}
	regions := []marketRegions{}
	types := []marketTypes{}
	stations = make(map[int64]int64)

	// Scope to allow garbage colect to reclaim startup data.
	{
		type crestRegions_s struct {
			TotalCount_Str string
			Items          []struct {
				HRef string
				Name string
			}
			PageCount  int64
			TotalCount int64
		}

		type crestTypes_s struct {
			TotalCount_Str string
			Items          []struct {
				Type struct {
					ID   int64
					Name string
				}
			}
			PageCount  int64
			TotalCount int64
			Next       struct {
				HRef string `json:"href,omitempty"`
			}
		}

		// Collect Regions from CREST servers.
		crestRegions := crestRegions_s{}
		_, err = crestSession.Get(crestUrl+"regions/", nil, &crestRegions, nil)
		fatalCheck(err)

		// Extract the ID out of the URI.
		for _, r := range crestRegions.Items {
			re := regexp.MustCompile("([0-9]+)")
			regionID, _ := strconv.ParseInt(re.FindString(r.HRef), 10, 64)
			regions = append(regions, marketRegions{regionID, r.Name})
		}
		log.Printf("Loaded %d Regions", len(regions))

		// Collect Types from CREST servers.
		crestTypes := crestTypes_s{}
		_, err = crestSession.Get(crestUrl+"market/types/", nil, &crestTypes, nil)
		fatalCheck(err)

		// Translate the first page.
		for _, t := range crestTypes.Items {
			types = append(types, marketTypes{t.Type.ID, t.Type.Name})
		}

		// Loop the next pages.
		for {
			last := crestTypes.Next.HRef

			_, err = crestSession.Get(crestTypes.Next.HRef, nil, &crestTypes, nil)
			fatalCheck(err)
			for _, t := range crestTypes.Items {
				types = append(types, marketTypes{t.Type.ID, t.Type.Name})
			}

			if crestTypes.Next.HRef == last {
				break
			}
		}

		log.Printf("Loaded %d Types", len(types))

		// Load NPC stations from file.
		file, err := os.Open("stations")
		fatalCheck(err)
		defer file.Close()
		reader := csv.NewReader(file)
		reader.Comma = '\t' // Tab delimited.

		for {
//.........這裏部分代碼省略.........
開發者ID:antihax,項目名稱:CrestEMDRBridge,代碼行數:101,代碼來源:CrestEMDRBridge.go


注:本文中的github.com/jmcvetta/napping.Session.Get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。