本文整理汇总了Golang中net/url.Values.Set方法的典型用法代码示例。如果您正苦于以下问题:Golang Values.Set方法的具体用法?Golang Values.Set怎么用?Golang Values.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/url.Values
的用法示例。
在下文中一共展示了Values.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetFollowersListAll
// Like GetFollowersList, but returns a channel instead of a cursor and pre-fetches the remaining results
// This channel is closed once all values have been fetched
func (a TwitterApi) GetFollowersListAll(v url.Values) (result chan FollowersPage) {
result = make(chan FollowersPage)
if v == nil {
v = url.Values{}
}
go func(a TwitterApi, v url.Values, result chan FollowersPage) {
// Cursor defaults to the first page ("-1")
next_cursor := "-1"
for {
v.Set("cursor", next_cursor)
c, err := a.GetFollowersList(v)
// throttledQuery() handles all rate-limiting errors
// if GetFollowersList() returns an error, it must be a different kind of error
result <- FollowersPage{c.Users, err}
next_cursor = c.Next_cursor_str
if next_cursor == "0" {
close(result)
break
}
}
}(a, v, result)
return result
}
示例2: Values
func (plan *Plan) Values(values *url.Values) error {
if plan == nil {
// TODO: Throw error
}
if plan.ID == "" {
// TODO: Throw error
}
if plan.Name == "" {
// TODO: Throw error
}
if plan.Amount <= 0 {
// TODO: Throw error
}
if plan.Currency != "USD" {
// TODO: Throw error
}
if plan.Interval != "month" && plan.Interval != "year" {
// TODO: Throw error
}
if plan.TrialDays > 0 {
values.Set("trial_period_days", strconv.Itoa(plan.TrialDays))
}
values.Set("id", plan.ID)
values.Set("amount", strconv.Itoa(plan.Amount))
values.Set("currency", plan.Currency)
values.Set("interval", plan.Interval)
values.Set("name", plan.Name)
return nil
}
示例3: getUpdates
func getUpdates(token string, offset int, timeout int) (updates []Update, err error) {
params := url.Values{}
params.Set("offset", strconv.Itoa(offset))
params.Set("timeout", strconv.Itoa(timeout))
updatesJSON, err := sendCommand("getUpdates", token, params)
if err != nil {
return
}
var updatesRecieved struct {
Ok bool
Result []Update
Description string
}
err = json.Unmarshal(updatesJSON, &updatesRecieved)
if err != nil {
return
}
if !updatesRecieved.Ok {
err = FetchError{updatesRecieved.Description}
return
}
updates = updatesRecieved.Result
return
}
示例4: 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
}
示例5: 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
}
示例6: List
func (b *Bucket) List(prefix, delimiter string) (*ListBucketResult, error) {
vals := url.Values{}
vals.Set("prefix", prefix)
if delimiter != "" {
vals.Set("delimiter", delimiter)
}
req, err := http.NewRequest("GET", b.URL("", vals).String(), nil)
if err != nil {
return nil, err
}
req.Header.Set("x-amz-content-sha256", fmt.Sprintf("%x", sha256.Sum256(nil)))
b.Service.sign(req)
resp, err := b.Service.do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected http status code: %d", resp.StatusCode)
}
list := new(ListBucketResult)
err = xml.NewDecoder(resp.Body).Decode(list)
if err != nil {
return nil, fmt.Errorf("unable to decode response body: %s", err)
}
return list, nil
}
示例7: TestGUIArchivePostCurrent
func (s *guiArchiveSuite) TestGUIArchivePostCurrent(c *gc.C) {
// Add an existing GUI archive and set it as the current one.
storage, err := s.State.GUIStorage()
c.Assert(err, jc.ErrorIsNil)
defer storage.Close()
vers := version.MustParse("2.0.47")
setupGUIArchive(c, storage, vers.String(), nil)
err = s.State.GUISetVersion(vers)
c.Assert(err, jc.ErrorIsNil)
// Create a GUI archive to be uploaded.
r, hash, _ := makeGUIArchive(c, vers.String(), map[string]string{"filename": "content"})
// Prepare and send the request to upload a new GUI archive.
v := url.Values{}
v.Set("version", vers.String())
v.Set("hash", hash)
resp := s.authRequest(c, httpRequestParams{
method: "POST",
url: s.guiURL(c) + "?" + v.Encode(),
contentType: apiserver.BZMimeType,
body: r,
})
// Check that the response reflects a successful upload.
body := assertResponse(c, resp, http.StatusOK, params.ContentTypeJSON)
var jsonResponse params.GUIArchiveVersion
err = json.Unmarshal(body, &jsonResponse)
c.Assert(err, jc.ErrorIsNil, gc.Commentf("body: %s", body))
c.Assert(jsonResponse, jc.DeepEquals, params.GUIArchiveVersion{
Version: vers,
SHA256: hash,
Current: true,
})
}
示例8: Send
// Send sends an SMS
func Send(recipient string, message string) error {
endpoint := fmt.Sprintf("https://api.twilio.com/2010-04-01/Accounts/%s/Messages.json", user)
data := url.Values{}
data.Set("From", from)
data.Set("To", recipient)
data.Set("Body", message)
body := data.Encode()
fmt.Printf("SENDING SMS:%s BODY:%s\n", endpoint, body)
request, err := http.NewRequest("POST", endpoint, strings.NewReader(body))
if err != nil {
return err
}
request.SetBasicAuth(user, secret)
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
response, err := http.DefaultClient.Do(request)
if err != nil {
return err
}
if response.StatusCode != http.StatusCreated {
fmt.Sprintf("Error sending SMS:%v\n", response)
return fmt.Errorf("SMS send failed with status:%d", response.StatusCode)
}
return nil
}
示例9: CmdPush
func (cli *DockerCli) CmdPush(args ...string) error {
cmd := Subcmd("push", "[OPTION] NAME", "Push an image or a repository to the registry")
registry := cmd.String("registry", "", "Registry host to push the image to")
if err := cmd.Parse(args); err != nil {
return nil
}
name := cmd.Arg(0)
if name == "" {
cmd.Usage()
return nil
}
username, err := cli.checkIfLogged(*registry == "", "push")
if err != nil {
return err
}
if len(strings.SplitN(name, "/", 2)) == 1 {
return fmt.Errorf("Impossible to push a \"root\" repository. Please rename your repository in <user>/<repo> (ex: %s/%s)", username, name)
}
v := url.Values{}
v.Set("registry", *registry)
if err := cli.stream("POST", "/images/"+name+"/push?"+v.Encode(), nil, os.Stdout); err != nil {
return err
}
return nil
}
示例10: buildURL
// buildURL builds the URL for the operation.
func (s *IndicesExistsTypeService) buildURL() (string, url.Values, error) {
// Build URL
path, err := uritemplates.Expand("/{index}/{type}", map[string]string{
"index": strings.Join(s.index, ","),
"type": strings.Join(s.typ, ","),
})
if err != nil {
return "", url.Values{}, err
}
// Add query string parameters
params := url.Values{}
if s.pretty {
params.Set("pretty", "1")
}
if s.ignoreUnavailable != nil {
params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable))
}
if s.allowNoIndices != nil {
params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices))
}
if s.expandWildcards != "" {
params.Set("expand_wildcards", s.expandWildcards)
}
if s.local != nil {
params.Set("local", fmt.Sprintf("%v", *s.local))
}
return path, params, nil
}
示例11: SendAuthenticatedHTTPRequest
func (k *Kraken) SendAuthenticatedHTTPRequest(method string, values url.Values) (interface{}, error) {
path := fmt.Sprintf("/%s/private/%s", KRAKEN_API_VERSION, method)
values.Set("nonce", strconv.FormatInt(time.Now().UnixNano(), 10))
secret, err := Base64Decode(k.APISecret)
if err != nil {
return nil, err
}
shasum := GetSHA256([]byte(values.Get("nonce") + values.Encode()))
signature := Base64Encode(GetHMAC(HASH_SHA512, append([]byte(path), shasum...), secret))
if k.Verbose {
log.Printf("Sending POST request to %s, path: %s.", KRAKEN_API_URL, path)
}
headers := make(map[string]string)
headers["API-Key"] = k.ClientKey
headers["API-Sign"] = signature
resp, err := SendHTTPRequest("POST", KRAKEN_API_URL+path, headers, strings.NewReader(values.Encode()))
if err != nil {
return nil, err
}
if k.Verbose {
log.Printf("Recieved raw: \n%s\n", resp)
}
return resp, nil
}
示例12: List
// List calls google.com/cloudprint/list to get all GCP printers assigned
// to this connector.
//
// Returns map of GCPID => printer name. GCPID is unique to GCP; printer name
// should be unique to CUPS. Use Printer to get details about each printer.
func (gcp *GoogleCloudPrint) List() (map[string]string, error) {
form := url.Values{}
form.Set("proxy", gcp.proxyName)
form.Set("extra_fields", "-tags")
responseBody, _, _, err := postWithRetry(gcp.robotClient, gcp.baseURL+"list", form)
if err != nil {
return nil, err
}
var listData struct {
Printers []struct {
ID string `json:"id"`
Name string `json:"name"`
}
}
if err = json.Unmarshal(responseBody, &listData); err != nil {
return nil, err
}
printers := make(map[string]string, len(listData.Printers))
for _, p := range listData.Printers {
printers[p.ID] = p.Name
}
return printers, nil
}
示例13: GetTradesHistory
func (k *Kraken) GetTradesHistory(tradeType string, showRelatedTrades bool, start, end, offset int64) {
values := url.Values{}
if len(tradeType) > 0 {
values.Set("aclass", tradeType)
}
if showRelatedTrades {
values.Set("trades", "true")
}
if start != 0 {
values.Set("start", strconv.FormatInt(start, 10))
}
if end != 0 {
values.Set("end", strconv.FormatInt(end, 10))
}
if offset != 0 {
values.Set("offset", strconv.FormatInt(offset, 10))
}
result, err := k.SendAuthenticatedHTTPRequest(KRAKEN_TRADES_HISTORY, values)
if err != nil {
log.Println(err)
return
}
log.Println(result)
}
示例14: 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
}
示例15: doObjectStoreAddImage
func doObjectStoreAddImage(c *cli.Context) error {
var err error
v := url.Values{}
objectstoreUUID, err := getUUID(c, KEY_OBJECTSTORE, true, err)
imageUUID, err := getUUID(c, KEY_IMAGE, false, err)
imageName, err := getName(c, "image-name", false, err)
if err != nil {
return err
}
imageFile := c.String("image-file")
if imageFile == "" {
return genRequiredMissingError("image-file")
}
imageConfig := api.ObjectStoreImageConfig{
ImageFile: imageFile,
}
if imageUUID != "" {
v.Set(KEY_IMAGE, imageUUID)
}
if imageName != "" {
v.Set("image-name", imageName)
}
request := "/objectstores/" + objectstoreUUID + "/images/add?" + v.Encode()
return sendRequestAndPrint("POST", request, imageConfig)
}