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


Golang Values.Get方法代码示例

本文整理汇总了Golang中url.Values.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Values.Get方法的具体用法?Golang Values.Get怎么用?Golang Values.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在url.Values的用法示例。


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

示例1: VerifyValues

// Like Verify on a parsed URL
func VerifyValues(values url.Values) (grant bool, identifier string, err error) {
	err = nil

	var postArgs url.Values
	postArgs = url.Values(map[string][]string{})

	// Create the url
	URLEndPoint := values.Get("openid.op_endpoint")
	if URLEndPoint == "" {
		log.Printf("no openid.op_endpoint")
		return false, "", errors.New("no openid.op_endpoint")
	}
	for k, v := range values {
		postArgs[k] = v
	}
	postArgs.Set("openid.mode", "check_authentication")
	postContent := postArgs.Encode()

	// Post the request
	var client = new(http.Client)
	postReader := bytes.NewBuffer([]byte(postContent))
	response, err := client.Post(URLEndPoint, "application/x-www-form-urlencoded", postReader)
	if err != nil {
		log.Printf("VerifyValues failed at post")
		return false, "", err
	}

	// Parse the response
	// Convert the reader
	// We limit the size of the response to 1024 bytes but it should be large enough for most cases
	buffer := make([]byte, 1024)
	_, err = response.Body.Read(buffer)
	if err != nil {
		log.Printf("VerifyValues failed reading response")
		return false, "", err
	}

	// Check for ns
	rematch := REVerifyDirectNs.FindSubmatch(buffer)
	if rematch == nil {
		return false, "", errors.New("VerifyValues: ns value not found on the response of the OP")
	}
	nsValue := string(rematch[1])
	if !bytes.Equal([]byte(nsValue), []byte("http://specs.openid.net/auth/2.0")) {
		return false, "", errors.New("VerifyValues: ns value not correct: " + nsValue)
	}

	// Check for is_valid
	match, err := regexp.Match(REVerifyDirectIsValid, buffer)
	if err != nil {
		return false, "", err
	}

	identifier = values.Get("openid.claimed_id")
	if !match {
		log.Printf("no is_valid:true in \"%s\"", buffer)
	}

	return match, identifier, nil
}
开发者ID:tobi,项目名称:go-openid,代码行数:61,代码来源:verify.go

示例2: SortedEscape

// (2011-06-21) - The standard go http.Values.Escape
// works properly for SQS  and S3, but it should be
// noted that at least SDB requiers more to be escaped
// than is officially standard.
//
// Sorted Escape also sorts the keys before joining them (needed
// for canonicalization).
func SortedEscape(v url.Values) (out string) {
	keys := []string{}
	for k := range v {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	for k := range keys {
		if k > 0 {
			out += "&"
		}
		// out += http.URLEscape(keys[k]) + "=" + http.URLEscape(v.Get(keys[k]))
		out += escape(keys[k]) + "=" + escape(v.Get(keys[k]))
	}
	return
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:22,代码来源:escape.go

示例3: retrieveInfo

func retrieveInfo(client oauth2_client.OAuth2Client, scope, userId, projection, id string, m url.Values, value interface{}) (err os.Error) {
	var useUserId string
	if len(userId) <= 0 {
		useUserId = GOOGLE_DEFAULT_USER_ID
	} else {
		useUserId = url.QueryEscape(userId)
	}
	if len(projection) <= 0 {
		projection = GOOGLE_DEFAULT_PROJECTION
	}
	headers := make(http.Header)
	headers.Set("GData-Version", "3.0")
	if m == nil {
		m = make(url.Values)
	}
	if len(m.Get(CONTACTS_ALT_PARAM)) <= 0 {
		m.Set(CONTACTS_ALT_PARAM, "json")
	}
	uri := GOOGLE_FEEDS_API_ENDPOINT
	for _, s := range []string{scope, useUserId, projection, id} {
		if len(s) > 0 {
			if uri[len(uri)-1] != '/' {
				uri += "/"
			}
			uri += s
		}
	}
	resp, _, err := oauth2_client.AuthorizedGetRequest(client, headers, uri, m)
	if err != nil {
		return err
	}
	if resp != nil {
		if resp.StatusCode >= 400 {
			b, _ := ioutil.ReadAll(resp.Body)
			err = os.NewError(string(b))
		} else {
			err = json.NewDecoder(resp.Body).Decode(value)
		}
	}
	return err
}
开发者ID:pombredanne,项目名称:contacts.go,代码行数:41,代码来源:service.go


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