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


Golang Values.Encode方法代码示例

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


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

示例1: GetPodInfo

func (cli *HyperClient) GetPodInfo(podName string) (string, error) {
	// get the pod or container info before we start the exec
	v := url.Values{}
	v.Set("podName", podName)
	body, _, err := readBody(cli.call("GET", "/pod/info?"+v.Encode(), nil, nil))
	if err != nil {
		fmt.Printf("Error: %s\n", err)
		return "", err
	}

	out := engine.NewOutput()
	remoteInfo, err := out.AddEnv()
	if err != nil {
		return "", err
	}

	if _, err := out.Write(body); err != nil {
		fmt.Printf("Error reading remote info: %s", err)
		return "", err
	}
	out.Close()
	if remoteInfo.Exists("hostname") {
		hostname := remoteInfo.Get("hostname")
		if hostname == "" {
			return "", nil
		} else {
			return hostname, nil
		}
	}

	return "", nil
}
开发者ID:sulochan,项目名称:hyper,代码行数:32,代码来源:exec.go

示例2: Detect_language

func Detect_language(q string) string {
	var Url *url.URL
	Url, err := url.Parse("https://www.googleapis.com")
	if err != nil {
		fmt.Println(err)
	}

	Url.Path += "/language/translate/v2/detect"
	parameters := url.Values{}
	parameters.Add("q", q)
	parameters.Add("key", Google_key())
	Url.RawQuery = parameters.Encode()

	resp, err := http.Get(Url.String())
	if err != nil {
		fmt.Println(err)
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)

	var data gtresponse
	json.Unmarshal(body, &data)

	lang := data.Data.Detections[0][0].Language
	return lang
}
开发者ID:jackcook,项目名称:upptacka,代码行数:26,代码来源:translate.go

示例3: GetAccessToken

// Issue a request to exchange the current request token for an access token.
func (c *UserConfig) GetAccessToken(token string, verifier string, service *Service, client *http.Client) error {
	// This code used to error out if RequestTokenKey were empty, but
	// in the interest of being able to operate in a stateless manner this
	// has been removed.  If you want to make sure that the request token
	// is validated against what is being returned, populate the UserConfig
	// with a request token stored server-side somewhere, accessed by the
	// user's session.
	if c.RequestTokenKey != "" && c.RequestTokenKey != token {
		return fmt.Errorf("Returned token did not match request token")
	}
	c.Verifier = verifier
	data := url.Values{}
	if service.ClientConfig.CallbackURL != "" {
		data.Set("oauth_verifier", verifier)
	}
	body := strings.NewReader(data.Encode())
	request, err := http.NewRequest("POST", service.AccessURL, body)
	if err != nil {
		return err
	}
	request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	response, err := c.send(request, service, client)
	if err != nil {
		return err
	}
	err = c.parseAccessToken(response)
	return err
}
开发者ID:zchee,项目名称:scuttlebutt,代码行数:29,代码来源:userconfig.go

示例4: GetBlobSASURI

// GetBlobSASURI creates an URL to the specified blob which contains the Shared
// Access Signature with specified permissions and expiration time.
//
// See https://msdn.microsoft.com/en-us/library/azure/ee395415.aspx
func (b BlobStorageClient) GetBlobSASURI(container, name string, expiry time.Time, permissions string) (string, error) {
	var (
		signedPermissions = permissions
		blobURL           = b.GetBlobURL(container, name)
	)
	canonicalizedResource, err := b.client.buildCanonicalizedResource(blobURL)
	if err != nil {
		return "", err
	}
	signedExpiry := expiry.UTC().Format(time.RFC3339)
	signedResource := "b"

	stringToSign, err := blobSASStringToSign(b.client.apiVersion, canonicalizedResource, signedExpiry, signedPermissions)
	if err != nil {
		return "", err
	}

	sig := b.client.computeHmac256(stringToSign)
	sasParams := url.Values{
		"sv":  {b.client.apiVersion},
		"se":  {signedExpiry},
		"sr":  {signedResource},
		"sp":  {signedPermissions},
		"sig": {sig},
	}

	sasURL, err := url.Parse(blobURL)
	if err != nil {
		return "", err
	}
	sasURL.RawQuery = sasParams.Encode()
	return sasURL.String(), nil
}
开发者ID:RaulKite,项目名称:machine,代码行数:37,代码来源:blob.go

示例5: query

func (a *ListVersions) query() string {
	u := url.Values{}
	if a.Delimiter != "" {
		u.Add("delimiter", a.Delimiter)
	}
	if a.EncodingType != "" {
		u.Add("encoding-type", a.EncodingType)
	}
	if a.KeyMarker != "" {
		u.Add("key-marker", a.KeyMarker)
	}
	if a.MaxKeys != "" {
		u.Add("max-keys", a.MaxKeys)
	}
	if a.Prefix != "" {
		u.Add("prefix", a.Prefix)
	}
	if a.VersionIdMarker != "" {
		u.Add("verdion-id-marker", a.VersionIdMarker)
	}

	if len(u) > 0 {
		return u.Encode()
	}
	return ""
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:26,代码来源:list_versions.go

示例6: SendAuthenticatedHTTPRequest

func (o *OKCoin) SendAuthenticatedHTTPRequest(method string, v url.Values) (err error) {
	v.Set("api_key", o.PartnerID)
	hasher := GetMD5([]byte(v.Encode() + "&secret_key=" + o.SecretKey))
	v.Set("sign", strings.ToUpper(HexEncodeToString(hasher)))

	encoded := v.Encode()
	path := o.APIUrl + method

	if o.Verbose {
		log.Printf("Sending POST request to %s with params %s\n", path, encoded)
	}

	headers := make(map[string]string)
	headers["Content-Type"] = "application/x-www-form-urlencoded"

	resp, err := SendHTTPRequest("POST", path, headers, strings.NewReader(encoded))

	if err != nil {
		return err
	}

	if o.Verbose {
		log.Printf("Recieved raw: \n%s\n", resp)
	}

	return nil
}
开发者ID:jmaurice,项目名称:gocryptotrader,代码行数:27,代码来源:okcoinhttp.go

示例7: GetGameList

// GetGameList gets the game information from the DB.
func GetGameList(req GGLReq) (*GGLResp, error) {
	u, err := url.Parse(GDBURL)
	u.Path = GGLPath
	q := url.Values{}
	if req.Name == "" {
		return nil, fmt.Errorf("must provide Name")
	}
	q.Set("name", req.Name)
	if req.Platform != "" {
		q.Set("platform", req.Platform)
	}
	if req.Genre != "" {
		q.Set("genre", req.Genre)
	}
	u.RawQuery = q.Encode()
	resp, err := http.Get(u.String())
	if err != nil {
		return nil, fmt.Errorf("getting game list url:%s, error:%s", u, err)
	}
	defer resp.Body.Close()
	r := &GGLResp{}
	decoder := xml.NewDecoder(resp.Body)
	if err := decoder.Decode(r); err != nil {
		return nil, err
	}
	if r.XMLName.Local == "Error" {
		return nil, fmt.Errorf("GetGameList error: %s", r.err)
	} else {
		r.err = ""
	}
	return r, nil
}
开发者ID:pnicefor,项目名称:scraper,代码行数:33,代码来源:gdb.go

示例8: UploadSignedURL

// UploadSignedURL returns a signed URL that allows anyone holding the URL
// to upload the object at path. The signature is valid until expires.
// contenttype is a string like image/png
// path is the resource name in s3 terminalogy like images/ali.png [obviously exclusing the bucket name itself]
func (b *Bucket) UploadSignedURL(path, method, content_type string, expires time.Time) string {
	expire_date := expires.Unix()
	if method != "POST" {
		method = "PUT"
	}
	stringToSign := method + "\n\n" + content_type + "\n" + strconv.FormatInt(expire_date, 10) + "\n/" + b.Name + "/" + path
	fmt.Println("String to sign:\n", stringToSign)
	a := b.S3.Auth
	secretKey := a.SecretKey
	accessId := a.AccessKey
	mac := hmac.New(sha1.New, []byte(secretKey))
	mac.Write([]byte(stringToSign))
	macsum := mac.Sum(nil)
	signature := base64.StdEncoding.EncodeToString([]byte(macsum))
	signature = strings.TrimSpace(signature)

	signedurl, err := url.Parse("https://" + b.Name + ".s3.amazonaws.com/")
	if err != nil {
		log.Println("ERROR sining url for S3 upload", err)
		return ""
	}
	signedurl.Path += path
	params := url.Values{}
	params.Add("AWSAccessKeyId", accessId)
	params.Add("Expires", strconv.FormatInt(expire_date, 10))
	params.Add("Signature", signature)
	if a.Token() != "" {
		params.Add("token", a.Token())
	}

	signedurl.RawQuery = params.Encode()
	return signedurl.String()
}
开发者ID:crash2burn,项目名称:goamz,代码行数:37,代码来源:s3.go

示例9: init

func init() {
	storeBaseURI, err := url.Parse(cpiURL())
	if err != nil {
		panic(err)
	}

	storeSearchURI, err = storeBaseURI.Parse("search")
	if err != nil {
		panic(err)
	}

	v := url.Values{}
	v.Set("fields", strings.Join(getStructFields(remote.Snap{}), ","))
	storeSearchURI.RawQuery = v.Encode()

	storeDetailsURI, err = storeBaseURI.Parse("package/")

	if err != nil {
		panic(err)
	}

	storeBulkURI, err = storeBaseURI.Parse("click-metadata")
	if err != nil {
		panic(err)
	}
	storeBulkURI.RawQuery = v.Encode()
}
开发者ID:strukturag,项目名称:snappy,代码行数:27,代码来源:snapp.go

示例10: buildUrl

/*
Build URL for an API method call. Note that when using GET, we will also append query parameter to URL
*/
func (api *Api) buildUrl(method string, option map[string]string) string {
	q := url.Values{}
	for k, v := range option {
		q.Add(k, v)
	}
	return api.config.Endpoint(method) + "?" + q.Encode()
}
开发者ID:kureikain,项目名称:moonvuibot,代码行数:10,代码来源:api.go

示例11: RefreshSession

func (f *Force) RefreshSession() (err error, emessages []ForceError) {
	attrs := url.Values{}
	attrs.Set("grant_type", "refresh_token")
	attrs.Set("refresh_token", f.Credentials.RefreshToken)
	attrs.Set("client_id", ClientId)
	attrs.Set("format", "json")

	postVars := attrs.Encode()
	req, err := httpRequest("POST", f.refreshTokenURL(), bytes.NewReader([]byte(postVars)))
	if err != nil {
		return
	}
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	fmt.Println("Refreshing Session Token")
	res, err := doRequest(req)
	if err != nil {
		return
	}
	defer res.Body.Close()
	body, err := ioutil.ReadAll(res.Body)
	if res.StatusCode != 200 {
		ErrorAndExit("Failed to refresh session.  Please run `force login`.")
		return
	}
	if err != nil {
		return
	}

	var result ForceCredentials
	json.Unmarshal(body, &result)
	f.UpdateCredentials(result)
	LogAuth()
	return
}
开发者ID:heroku,项目名称:force,代码行数:34,代码来源:force.go

示例12: Request

func (self *ReportClient) Request(path string, params map[string]string) (ret interface{}, err error) {
	args := make(map[string]string, len(params)+3)
	for k, v := range params {
		args[k] = v
	}

	args["api_key"] = self.apiKey
	args["expire"] = fmt.Sprintf("%d", time.Now().Unix()+600)
	args["sig"] = hashArgs(self.apiSecret, args)

	query := url.Values{}
	for k, v := range args {
		query.Add(k, v)
	}
	url := fmt.Sprintf("%s/%s/%s/?%s", ENDPOINT, VERSION, path, query.Encode())
	resp, urlerr := http.Get(url)
	if urlerr != nil {
		err = urlerr
		return
	}

	defer resp.Body.Close()
	body, httperr := ioutil.ReadAll(resp.Body)
	if httperr != nil {
		err = httperr
		return
	}
	jsonerr := json.Unmarshal(body, &ret)
	if jsonerr != nil {
		err = jsonerr
		return
	}
	return ret, nil
}
开发者ID:joeatwork,项目名称:blinky,代码行数:34,代码来源:mixpanel.go

示例13: SendAuthenticatedHTTPRequest

func (c *Cryptsy) SendAuthenticatedHTTPRequest(method, path string, params url.Values) (err error) {
	nonce := strconv.FormatInt(time.Now().Unix(), 10)
	params.Set("nonce", nonce)
	encoded := params.Encode()
	hmac := GetHMAC(HASH_SHA512, []byte(encoded), []byte(c.APISecret))
	readStr := ""

	if method == "GET" || method == "DELETE" {
		path += "?" + encoded
	} else if method == "POST" {
		readStr = encoded
	}

	if c.Verbose {
		log.Printf("Sending %s request to %s with params %s\n", method, path, encoded)
	}

	headers := make(map[string]string)
	headers["Key"] = c.APIKey
	headers["Sign"] = HexEncodeToString(hmac)
	headers["Content-Type"] = "application/x-www-form-urlencoded"

	resp, err := SendHTTPRequest(method, path, headers, strings.NewReader(readStr))

	if err != nil {
		return err
	}

	if c.Verbose {
		log.Printf("Recieved raw: \n%s\n", resp)
	}

	return nil
}
开发者ID:jmaurice,项目名称:gocryptotrader,代码行数:34,代码来源:cryptsyhttp.go

示例14: CmdRestart

// CmdRestart restarts one or more running containers.
//
// Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]
func (cli *DockerCli) CmdRestart(args ...string) error {
	cmd := cli.Subcmd("restart", "CONTAINER [CONTAINER...]", "Restart a running container", true)
	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing the container")
	cmd.Require(flag.Min, 1)

	cmd.ParseFlags(args, true)

	v := url.Values{}
	v.Set("t", strconv.Itoa(*nSeconds))

	var errNames []string
	for _, name := range cmd.Args() {
		_, _, err := readBody(cli.call("POST", "/containers/"+name+"/restart?"+v.Encode(), nil, nil))
		if err != nil {
			fmt.Fprintf(cli.err, "%s\n", err)
			errNames = append(errNames, name)
		} else {
			fmt.Fprintf(cli.out, "%s\n", name)
		}
	}
	if len(errNames) > 0 {
		return fmt.Errorf("Error: failed to restart containers: %v", errNames)
	}
	return nil
}
开发者ID:colebrumley,项目名称:docker,代码行数:28,代码来源:restart.go

示例15: postMessage

func postMessage(path, room, message string) ([]byte, error) {
	data := url.Values{}
	data.Set("room_id", room)
	data.Add("message", message)
	data.Add("from", "hcl")
	data.Add("notify", "1")
	data.Add("color", "green")

	req, err := http.NewRequest("POST", path, bytes.NewBufferString(data.Encode()))
	if err != nil {
		fmt.Println("postMessage ERROR: ", err)
	}

	// for v2 only
	//authHeader := fmt.Sprintf("Bearer %s", token)
	//req.Header.Add("Authentication", authHeader)
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("client do ERROR: ", err)
	}

	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Read body ERROR: ", err)
	}
	return body, nil
}
开发者ID:sendgrid-ops,项目名称:hcl,代码行数:31,代码来源:hipchat.go


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