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


Golang ServiceClient.Request方法代碼示例

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


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

示例1: Get

// Get is a function that retrieves the metadata of a container. To extract just
// the custom metadata, pass the GetResult response to the ExtractMetadata
// function.
func Get(c *gophercloud.ServiceClient, containerName string) (r GetResult) {
	resp, err := c.Request("HEAD", getURL(c, containerName), &gophercloud.RequestOpts{
		OkCodes: []int{200, 204},
	})
	if resp != nil {
		r.Header = resp.Header
	}
	r.Err = err
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:13,代碼來源:requests.go

示例2: Validate

// Validate determines if a specified token is valid or not.
func Validate(c *gophercloud.ServiceClient, token string) (bool, error) {
	resp, err := c.Request("HEAD", tokenURL(c), &gophercloud.RequestOpts{
		MoreHeaders: subjectTokenHeaders(c, token),
		OkCodes:     []int{204, 404},
	})
	if err != nil {
		return false, err
	}

	return resp.StatusCode == 204, nil
}
開發者ID:hyperhq,項目名稱:kubestack,代碼行數:12,代碼來源:requests.go

示例3: Update

// Update accepts a slice of Patch operations (Insertion, Append, Replacement or Removal) and
// updates an existing CDN service using the values provided. idOrURL can be either the service's
// URL or its ID. For example, both "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" and
// "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0"
// are valid options for idOrURL.
func Update(c *gophercloud.ServiceClient, idOrURL string, opts UpdateOpts) (r UpdateResult) {
	var url string
	if strings.Contains(idOrURL, "/") {
		url = idOrURL
	} else {
		url = updateURL(c, idOrURL)
	}

	b := make([]map[string]interface{}, len(opts))
	for i, patch := range opts {
		b[i] = patch.ToCDNServiceUpdateMap()
	}

	resp, err := c.Request("PATCH", url, &gophercloud.RequestOpts{
		JSONBody: &b,
		OkCodes:  []int{202},
	})
	r.Header = resp.Header
	r.Err = err
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:26,代碼來源:requests.go

示例4: Update

// Update is a function that creates, updates, or deletes an account's metadata.
// To extract the headers returned, call the Extract method on the UpdateResult.
func Update(c *gophercloud.ServiceClient, opts UpdateOptsBuilder) (r UpdateResult) {
	h := make(map[string]string)
	if opts != nil {
		headers, err := opts.ToAccountUpdateMap()
		if err != nil {
			r.Err = err
			return
		}
		for k, v := range headers {
			h[k] = v
		}
	}
	resp, err := c.Request("POST", updateURL(c), &gophercloud.RequestOpts{
		MoreHeaders: h,
		OkCodes:     []int{201, 202, 204},
	})
	if resp != nil {
		r.Header = resp.Header
	}
	r.Err = err
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:24,代碼來源:requests.go

示例5: Create

// Create is a function that creates a new container.
func Create(c *gophercloud.ServiceClient, containerName string, opts CreateOptsBuilder) (r CreateResult) {
	h := make(map[string]string)
	if opts != nil {
		headers, err := opts.ToContainerCreateMap()
		if err != nil {
			r.Err = err
			return
		}
		for k, v := range headers {
			h[k] = v
		}
	}
	resp, err := c.Request("PUT", createURL(c, containerName), &gophercloud.RequestOpts{
		MoreHeaders: h,
		OkCodes:     []int{201, 202, 204},
	})
	if resp != nil {
		r.Header = resp.Header
	}
	r.Err = err
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:23,代碼來源:requests.go

示例6: Copy

// Copy is a function that copies one object to another.
func Copy(c *gophercloud.ServiceClient, containerName, objectName string, opts CopyOptsBuilder) (r CopyResult) {
	h := make(map[string]string)
	headers, err := opts.ToObjectCopyMap()
	if err != nil {
		r.Err = err
		return
	}

	for k, v := range headers {
		h[k] = v
	}

	url := copyURL(c, containerName, objectName)
	resp, err := c.Request("COPY", url, &gophercloud.RequestOpts{
		MoreHeaders: h,
		OkCodes:     []int{201},
	})
	if resp != nil {
		r.Header = resp.Header
	}
	r.Err = err
	return
}
開發者ID:jrperritt,項目名稱:gophercloud-1,代碼行數:24,代碼來源:requests.go


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