本文整理匯總了Golang中github.com/rackspace/gophercloud.ServiceClient.AuthenticatedHeaders方法的典型用法代碼示例。如果您正苦於以下問題:Golang ServiceClient.AuthenticatedHeaders方法的具體用法?Golang ServiceClient.AuthenticatedHeaders怎麽用?Golang ServiceClient.AuthenticatedHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rackspace/gophercloud.ServiceClient
的用法示例。
在下文中一共展示了ServiceClient.AuthenticatedHeaders方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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.Reader, opts CreateOptsBuilder) CreateResult {
var res CreateResult
url := createURL(c, containerName, objectName)
h := c.AuthenticatedHeaders()
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
}
contentType := h["Content-Type"]
resp, err := perigee.Request("PUT", url, perigee.Options{
ContentType: contentType,
ReqBody: content,
MoreHeaders: h,
OkCodes: []int{201, 202},
})
res.Header = resp.HttpResponse.Header
res.Err = err
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 := perigee.Request("POST", url, perigee.Options{
MoreHeaders: h,
OkCodes: []int{202},
})
res.Header = resp.HttpResponse.Header
res.Err = err
return res
}
示例3: Update
// Update allows floating IP resources to be updated. Currently, the only way to
// "update" a floating IP is to associate it with a new internal port, or
// disassociated it from all ports. See UpdateOpts for instructions of how to
// do this.
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResult {
type floatingIP struct {
PortID *string `json:"port_id"`
}
type request struct {
FloatingIP floatingIP `json:"floatingip"`
}
var portID *string
if opts.PortID == "" {
portID = nil
} else {
portID = &opts.PortID
}
reqBody := request{FloatingIP: floatingIP{PortID: portID}}
// Send request to API
var res UpdateResult
_, res.Err = perigee.Request("PUT", resourceURL(c, id), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res.Body,
OkCodes: []int{200},
})
return res
}
示例4: Create
// Create accepts a CreateOpts struct and uses the values to create a new
// logical router. When it is created, the router does not have an internal
// interface - it is not associated to any subnet.
//
// You can optionally specify an external gateway for a router using the
// GatewayInfo struct. The external gateway for the router must be plugged into
// an external network (it is external if its `router:external' field is set to
// true).
func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
type router struct {
Name *string `json:"name,omitempty"`
AdminStateUp *bool `json:"admin_state_up,omitempty"`
TenantID *string `json:"tenant_id,omitempty"`
GatewayInfo *GatewayInfo `json:"external_gateway_info,omitempty"`
}
type request struct {
Router router `json:"router"`
}
reqBody := request{Router: router{
Name: gophercloud.MaybeString(opts.Name),
AdminStateUp: opts.AdminStateUp,
TenantID: gophercloud.MaybeString(opts.TenantID),
}}
if opts.GatewayInfo != nil {
reqBody.Router.GatewayInfo = opts.GatewayInfo
}
var res CreateResult
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res.Body,
OkCodes: []int{201},
})
return res
}
示例5: Create
// Create accepts a CreateOpts struct and uses the values to create a new
// load balancer pool.
func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
type pool struct {
Name string `json:"name"`
TenantID string `json:"tenant_id,omitempty"`
Protocol string `json:"protocol"`
SubnetID string `json:"subnet_id"`
LBMethod string `json:"lb_method"`
}
type request struct {
Pool pool `json:"pool"`
}
reqBody := request{Pool: pool{
Name: opts.Name,
TenantID: opts.TenantID,
Protocol: opts.Protocol,
SubnetID: opts.SubnetID,
LBMethod: opts.LBMethod,
}}
var res CreateResult
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res.Body,
OkCodes: []int{201},
})
return res
}
示例6: Create
// Create is an operation which provisions a new security group with default
// security group rules for the IPv4 and IPv6 ether types.
func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
var res CreateResult
// Validate required opts
if opts.Name == "" {
res.Err = errNameRequired
return res
}
type secgroup struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
}
type request struct {
SecGroup secgroup `json:"security_group"`
}
reqBody := request{SecGroup: secgroup{
Name: opts.Name,
Description: opts.Description,
}}
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res.Body,
OkCodes: []int{201},
})
return res
}
示例7: Enable
// Enable is a function that enables/disables a CDN container.
func Enable(c *gophercloud.ServiceClient, containerName string, opts EnableOptsBuilder) EnableResult {
var res EnableResult
h := c.AuthenticatedHeaders()
if opts != nil {
headers, err := opts.ToCDNContainerEnableMap()
if err != nil {
res.Err = err
return res
}
for k, v := range headers {
h[k] = v
}
}
resp, err := c.Request("PUT", enableURL(c, containerName), gophercloud.RequestOpts{
MoreHeaders: h,
OkCodes: []int{201, 202, 204},
})
if resp != nil {
res.Header = resp.Header
}
res.Err = err
return res
}
示例8: Update
// Update changes an existing endpoint with new data.
// All fields are optional in the provided EndpointOpts.
func Update(client *gophercloud.ServiceClient, endpointID string, opts EndpointOpts) UpdateResult {
type endpoint struct {
Interface *string `json:"interface,omitempty"`
Name *string `json:"name,omitempty"`
Region *string `json:"region,omitempty"`
URL *string `json:"url,omitempty"`
ServiceID *string `json:"service_id,omitempty"`
}
type request struct {
Endpoint endpoint `json:"endpoint"`
}
reqBody := request{Endpoint: endpoint{}}
reqBody.Endpoint.Interface = gophercloud.MaybeString(string(opts.Availability))
reqBody.Endpoint.Name = gophercloud.MaybeString(opts.Name)
reqBody.Endpoint.Region = gophercloud.MaybeString(opts.Region)
reqBody.Endpoint.URL = gophercloud.MaybeString(opts.URL)
reqBody.Endpoint.ServiceID = gophercloud.MaybeString(opts.ServiceID)
var result UpdateResult
_, result.Err = perigee.Request("PATCH", endpointURL(client, endpointID), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &result.Body,
OkCodes: []int{200},
})
return result
}
示例9: 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
}
示例10: 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
}
示例11: 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
}
示例12: 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
}
示例13: Delete
// Delete will delete objects or containers in bulk.
func Delete(c *gophercloud.ServiceClient, opts DeleteOptsBuilder) DeleteResult {
var res DeleteResult
if opts == nil {
return res
}
reqString, err := opts.ToBulkDeleteBody()
if err != nil {
res.Err = err
return res
}
reqBody := strings.NewReader(reqString)
resp, err := perigee.Request("DELETE", deleteURL(c), perigee.Options{
ContentType: "text/plain",
MoreHeaders: c.AuthenticatedHeaders(),
OkCodes: []int{200},
ReqBody: reqBody,
Results: &res.Body,
})
res.Header = resp.HttpResponse.Header
res.Err = err
return res
}
示例14: AddInterface
// AddInterface attaches a subnet to an internal router interface. You must
// specify either a SubnetID or PortID in the request body. If you specify both,
// the operation will fail and an error will be returned.
//
// If you specify a SubnetID, the gateway IP address for that particular subnet
// is used to create the router interface. Alternatively, if you specify a
// PortID, the IP address associated with the port is used to create the router
// interface.
//
// If you reference a port that is associated with multiple IP addresses, or
// if the port is associated with zero IP addresses, the operation will fail and
// a 400 Bad Request error will be returned.
//
// If you reference a port already in use, the operation will fail and a 409
// Conflict error will be returned.
//
// The PortID that is returned after using Extract() on the result of this
// operation can either be the same PortID passed in or, on the other hand, the
// identifier of a new port created by this operation. After the operation
// completes, the device ID of the port is set to the router ID, and the
// device owner attribute is set to `network:router_interface'.
func AddInterface(c *gophercloud.ServiceClient, id string, opts InterfaceOpts) InterfaceResult {
var res InterfaceResult
// Validate
if (opts.SubnetID == "" && opts.PortID == "") || (opts.SubnetID != "" && opts.PortID != "") {
res.Err = errInvalidInterfaceOpts
return res
}
type request struct {
SubnetID string `json:"subnet_id,omitempty"`
PortID string `json:"port_id,omitempty"`
}
body := request{SubnetID: opts.SubnetID, PortID: opts.PortID}
_, res.Err = perigee.Request("PUT", addInterfaceURL(c, id), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
ReqBody: &body,
Results: &res.Body,
OkCodes: []int{200},
})
return res
}
示例15: Delete
// Delete will delete the volume type with the provided ID.
func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
var res DeleteResult
_, res.Err = client.Request("DELETE", deleteURL(client, id), gophercloud.RequestOpts{
MoreHeaders: client.AuthenticatedHeaders(),
OkCodes: []int{202},
})
return res
}