本文整理汇总了Golang中github.com/jrperritt/rack/internal/github.com/rackspace/gophercloud.ServiceClient.Request方法的典型用法代码示例。如果您正苦于以下问题:Golang ServiceClient.Request方法的具体用法?Golang ServiceClient.Request怎么用?Golang ServiceClient.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jrperritt/rack/internal/github.com/rackspace/gophercloud.ServiceClient
的用法示例。
在下文中一共展示了ServiceClient.Request方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Metadatum
// Metadatum requests the key-value pair with the given key for the given server ID.
func Metadatum(client *gophercloud.ServiceClient, id, key string) GetMetadatumResult {
var res GetMetadatumResult
_, res.Err = client.Request("GET", metadatumURL(client, id, key), gophercloud.RequestOpts{
JSONResponse: &res.Body,
})
return res
}
示例2: Update
// Update is a function that creates, updates, or deletes an object's metadata.
func Update(c *gophercloud.ServiceClient, containerName, objectName string, opts UpdateOptsBuilder) UpdateResult {
var res UpdateResult
h := c.AuthenticatedHeaders()
if opts != nil {
headers, err := opts.ToObjectUpdateMap()
if err != nil {
res.Err = err
return res
}
for k, v := range headers {
h[k] = v
}
}
url := updateURL(c, containerName, objectName)
resp, err := c.Request("POST", url, gophercloud.RequestOpts{
MoreHeaders: h,
})
if resp != nil {
res.Header = resp.Header
}
res.Err = err
return res
}
示例3: Copy
// Copy is a function that copies one object to another.
func Copy(c *gophercloud.ServiceClient, containerName, objectName string, opts CopyOptsBuilder) CopyResult {
var res CopyResult
h := c.AuthenticatedHeaders()
headers, err := opts.ToObjectCopyMap()
if err != nil {
res.Err = err
return res
}
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 {
res.Header = resp.Header
}
res.Err = err
return res
}
示例4: Download
// Download is a function that retrieves the content and metadata for an object.
// To extract just the content, pass the DownloadResult response to the
// ExtractContent function.
func Download(c *gophercloud.ServiceClient, containerName, objectName string, opts DownloadOptsBuilder) DownloadResult {
var res DownloadResult
url := downloadURL(c, containerName, objectName)
h := c.AuthenticatedHeaders()
if opts != nil {
headers, query, err := opts.ToObjectDownloadParams()
if err != nil {
res.Err = err
return res
}
for k, v := range headers {
h[k] = v
}
url += query
}
resp, err := c.Request("GET", url, gophercloud.RequestOpts{
MoreHeaders: h,
OkCodes: []int{200, 304},
})
if resp != nil {
res.Header = resp.Header
res.Body = resp.Body
}
res.Err = err
return res
}
示例5: Create
// Create is a function that creates a new object or replaces an existing object.
func Create(c *gophercloud.ServiceClient, containerName, objectName string, content io.ReadSeeker, opts CreateOptsBuilder) CreateResult {
var res CreateResult
url := createURL(c, containerName, objectName)
h := make(map[string]string)
if opts != nil {
headers, query, err := opts.ToObjectCreateParams()
if err != nil {
res.Err = err
return res
}
for k, v := range headers {
h[k] = v
}
url += query
}
ropts := gophercloud.RequestOpts{
RawBody: content,
MoreHeaders: h,
}
resp, err := c.Request("PUT", url, ropts)
if resp != nil {
res.Header = resp.Header
}
res.Err = err
return res
}
示例6: 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) UpdateResult {
var res UpdateResult
h := make(map[string]string)
if opts != nil {
headers, err := opts.ToAccountUpdateMap()
if err != nil {
res.Err = err
return res
}
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 {
res.Header = resp.Header
}
res.Err = err
return res
}
示例7: Get
// Get is a function that retrieves an account's metadata. To extract just the
// custom metadata, call the ExtractMetadata method on the GetResult. To extract
// all the headers that are returned (including the metadata), call the
// ExtractHeader method on the GetResult.
func Get(c *gophercloud.ServiceClient, opts GetOptsBuilder) GetResult {
var res GetResult
h := c.AuthenticatedHeaders()
if opts != nil {
headers, err := opts.ToAccountGetMap()
if err != nil {
res.Err = err
return res
}
for k, v := range headers {
h[k] = v
}
}
resp, err := c.Request("HEAD", getURL(c), gophercloud.RequestOpts{
MoreHeaders: h,
OkCodes: []int{204},
})
if resp != nil {
res.Header = resp.Header
}
res.Err = err
return res
}
示例8: Create
// Create is a function that creates a new object or replaces an existing object. If the returned response's ETag
// header fails to match the local checksum, the failed request will automatically be retried up to a maximum of 3 times.
func Create(c *gophercloud.ServiceClient, containerName, objectName string, content io.ReadSeeker, opts CreateOptsBuilder) CreateResult {
var res CreateResult
url := createURL(c, containerName, objectName)
h := make(map[string]string)
if opts != nil {
headers, query, err := opts.ToObjectCreateParams()
if err != nil {
res.Err = err
return res
}
for k, v := range headers {
h[k] = v
}
url += query
}
hash := md5.New()
contentBuffer := bytes.NewBuffer([]byte{})
_, err := io.Copy(contentBuffer, io.TeeReader(content, hash))
if err != nil {
res.Err = err
return res
}
localChecksum := hash.Sum(nil)
h["ETag"] = fmt.Sprintf("%x", localChecksum)
ropts := gophercloud.RequestOpts{
RawBody: strings.NewReader(contentBuffer.String()),
MoreHeaders: h,
}
for i := 1; i <= 3; i++ {
resp, err := c.Request("PUT", url, ropts)
if resp != nil {
res.Header = resp.Header
}
if resp.Header.Get("ETag") == fmt.Sprintf("%x", localChecksum) {
res.Err = err
break
}
if i == 3 {
res.Err = fmt.Errorf("Local checksum does not match API ETag header")
return res
}
}
return res
}
示例9: Validate
// Validate determines if a specified token is valid or not.
func Validate(c *gophercloud.ServiceClient, token string) (bool, error) {
response, err := c.Request("HEAD", tokenURL(c), gophercloud.RequestOpts{
MoreHeaders: subjectTokenHeaders(c, token),
OkCodes: []int{204, 404},
})
if err != nil {
return false, err
}
return response.StatusCode == 204, nil
}
示例10: Get
// Get is a function that retrieves the metadata of an object. To extract just the custom
// metadata, pass the GetResult response to the ExtractMetadata function.
func Get(c *gophercloud.ServiceClient, containerName, objectName string, opts GetOptsBuilder) GetResult {
var res GetResult
url := getURL(c, containerName, objectName)
if opts != nil {
query, err := opts.ToObjectGetQuery()
if err != nil {
res.Err = err
return res
}
url += query
}
resp, err := c.Request("HEAD", url, gophercloud.RequestOpts{
OkCodes: []int{200, 204},
})
if resp != nil {
res.Header = resp.Header
}
res.Err = err
return res
}
示例11: Request
// Request performs an HTTP request and extracts the http.Response from the result.
func Request(client *gophercloud.ServiceClient, headers map[string]string, url string) (*http.Response, error) {
return client.Request("GET", url, gophercloud.RequestOpts{
MoreHeaders: headers,
OkCodes: []int{200, 204},
})
}