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


Golang Values.Encode方法代碼示例

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


在下文中一共展示了Values.Encode方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: NewPOSTTask

// NewPOSTTask creates a Task that will POST to a path with the given form data.
func NewPOSTTask(path string, params url.Values) *Task {
	h := make(http.Header)
	h.Set("Content-Type", "application/x-www-form-urlencoded")
	return &Task{
		Path:    path,
		Payload: []byte(params.Encode()),
		Header:  h,
		Method:  "POST",
	}
}
開發者ID:ashokgelal,項目名稱:gorilla,代碼行數:11,代碼來源:taskqueue.go

示例3: BuildQuery

// Build a URL+query string based on a given server URL, serverId and user
// input
func (s *ServerAuth) BuildQuery(serverId, user string) (query string) {
	queryValues := url.Values{
		"serverId": {serverId},
		"user":     {user},
	}

	queryUrl := s.baseUrl
	queryUrl.RawQuery = queryValues.Encode()

	return queryUrl.String()
}
開發者ID:huwenshu,項目名稱:chunkymonkey,代碼行數:13,代碼來源:server_auth.go

示例4: NewIssueComment

func (p *PullRequest) NewIssueComment(body string) (*Comment, os.Error) {
	url_ := fmt.Sprintf("%v/repos/%v/%v/issues/%v/comments", p.g.apiHost, p.Head.Repo.Name, p.Head.Repo.Owner.Login, p.Number)
	params := url.Values{}
	params.Add("body", body)
	out, err := p.g.makePostRequest(url_, strings.NewReader(params.Encode()))
	if err != nil {
		return nil, err
	}

	var comment Comment
	err = json.Unmarshal(out, &comment)
	if err != nil {
		return nil, err
	}

	return &comment, nil
}
開發者ID:supr,項目名稱:gohub,代碼行數:17,代碼來源:gohub.go

示例5: makeGetRequest

func (g *GoHub) makeGetRequest(url_ string, params url.Values) ([]byte, os.Error) {
	req, err := g.makeAuthRequest("GET", url_, strings.NewReader(params.Encode()))
	if err != nil {
		return nil, err
	}

	resp, err := g.client.Do(req)
	if err != nil {
		return nil, err
	}

	outbuf, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	return outbuf, err
}
開發者ID:supr,項目名稱:gohub,代碼行數:17,代碼來源:gohub.go

示例6: sesGet

func sesGet(data url.Values) (string, os.Error) {
	data.Add("AWSAccessKeyId", accessKey)
	urlstr := fmt.Sprintf("%s?%s", endpoint, data.Encode())
	endpointURL, _ := url.Parse(urlstr)
	headers := map[string][]string{}

	now := time.UTC()
	date := now.Format("Mon, 02 Jan 2006 15:04:05 -0700")
	headers["Date"] = []string{date}

	h := hmac.NewSHA256([]uint8(secretKey))
	h.Write([]uint8(date))
	signature := base64.StdEncoding.EncodeToString(h.Sum())
	auth := fmt.Sprintf("AWS3-HTTPS AWSAccessKeyId=%s, Algorithm=HmacSHA256, Signature=%s", accessKey, signature)
	headers["X-Amzn-Authorization"] = []string{auth}

	req := http.Request{
		URL:        endpointURL,
		Method:     "GET",
		ProtoMajor: 1,
		ProtoMinor: 1,
		Close:      true,
		Header:     headers,
	}

	r, err := http.DefaultClient.Do(&req)
	if err != nil {
		return "", err
	}

	resultbody, _ := ioutil.ReadAll(r.Body)
	r.Body.Close()

	if r.StatusCode != 200 {
		return "", os.NewError(string(resultbody))
	}

	return string(resultbody), nil
}
開發者ID:rsec,項目名稱:amzses,代碼行數:39,代碼來源:amzses.go

示例7: request

func (nc *Client) request(path string, data url.Values) (*response, os.Error) {
	// endpoint
	url := "https://api.notifo.com/v1" + path
	// encode request params
	reqBody := strings.NewReader(data.Encode())
	// build request
	req, err := http.NewRequest("POST", url, reqBody)
	if err != nil {
		return nil, err
	}
	req.Method = "POST"
	req.SetBasicAuth(nc.Username, nc.ApiSecret)
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	// make request
	client := new(http.Client)
	r, err := client.Do(req)
	// check connection
	if err != nil {
		return nil, err
	}
	defer r.Body.Close()
	// read response
	body, _ := ioutil.ReadAll(r.Body)
	// decode json
	response := new(response)
	err = json.Unmarshal(body, &response)
	if err != nil {
		return nil, err
	}
	// check for success code
	if response.Code != 2201 {
		return nil, fmt.Errorf("notifo: %s", response.Message)
	}
	// no error
	return response, nil
}
開發者ID:chrisfarms,項目名稱:notifo,代碼行數:36,代碼來源:notifo.go

示例8: PostForm

// PostForm issues a POST to the specified URL,
// with data's keys and values urlencoded as the request body.
//
// Caller should close r.Body when done reading from it.
func (c *Client) PostForm(url string, data url.Values) (r *Response, err os.Error) {
	return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
}
開發者ID:Sunmonds,項目名稱:gcc,代碼行數:7,代碼來源:client.go


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