Documentation ¶
Overview ¶
Package containers contains functionality for working with Object Storage container resources. A container serves as a logical namespace for objects that are placed inside it - an object with the same name in two different containers represents two different objects.
In addition to containing objects, you can also use the container to control access to objects by using an access control list (ACL).
Example to List Containers
listOpts := containers.ListOpts{ Full: true, } allPages, err := containers.List(objectStorageClient, listOpts).AllPages() if err != nil { panic(err) } allContainers, err := containers.ExtractInfo(allPages) if err != nil { panic(err) } for _, container := range allContainers { fmt.Printf("%+v\n", container) }
Example to List Only Container Names
listOpts := containers.ListOpts{ Full: false, } allPages, err := containers.List(objectStorageClient, listOpts).AllPages() if err != nil { panic(err) } allContainers, err := containers.ExtractNames(allPages) if err != nil { panic(err) } for _, container := range allContainers { fmt.Printf("%+v\n", container) }
Example to Create a Container
createOpts := containers.CreateOpts{ ContentType: "application/json", Metadata: map[string]string{ "foo": "bar", }, } container, err := containers.Create(objectStorageClient, createOpts).Extract() if err != nil { panic(err) }
Example to Update a Container
containerName := "my_container" updateOpts := containers.UpdateOpts{ Metadata: map[string]string{ "bar": "baz", }, } container, err := containers.Update(objectStorageClient, containerName, updateOpts).Extract() if err != nil { panic(err) }
Example to Delete a Container
containerName := "my_container" container, err := containers.Delete(objectStorageClient, containerName).Extract() if err != nil { panic(err) }
Index ¶
- func ExtractNames(page pagination.Page) ([]string, error)
- func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
- type Container
- type ContainerPage
- type CreateHeader
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type DeleteHeader
- type DeleteResult
- type GetHeader
- type GetResult
- type ListOpts
- type ListOptsBuilder
- type UpdateHeader
- type UpdateOpts
- type UpdateOptsBuilder
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractNames ¶
func ExtractNames(page pagination.Page) ([]string, error)
ExtractNames is a function that takes a ListResult and returns the containers' names.
func List ¶
func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
List is a function that retrieves containers associated with the account as well as account metadata. It returns a pager which can be iterated with the EachPage function.
Types ¶
type Container ¶
type Container struct { // The total number of bytes stored in the container. Bytes int64 `json:"bytes"` // The total number of objects stored in the container. Count int64 `json:"count"` // The name of the container. Name string `json:"name"` }
Container represents a container resource.
func ExtractInfo ¶
func ExtractInfo(r pagination.Page) ([]Container, error)
ExtractInfo is a function that takes a ListResult and returns the containers' information.
type ContainerPage ¶
type ContainerPage struct {
pagination.MarkerPageBase
}
ContainerPage is the page returned by a pager when traversing over a collection of containers.
func (ContainerPage) IsEmpty ¶
func (r ContainerPage) IsEmpty() (bool, error)
IsEmpty returns true if a ListResult contains no container names.
func (ContainerPage) LastMarker ¶
func (r ContainerPage) LastMarker() (string, error)
LastMarker returns the last container name in a ListResult.
type CreateHeader ¶
type CreateHeader struct { ContentLength int64 `json:"-"` ContentType string `json:"Content-Type"` Date time.Time `json:"-"` TransID string `json:"X-Trans-Id"` }
CreateHeader represents the headers returned in the response from a Create request.
func (*CreateHeader) UnmarshalJSON ¶
func (r *CreateHeader) UnmarshalJSON(b []byte) error
type CreateOpts ¶
type CreateOpts struct { Metadata map[string]string ContainerRead string `h:"X-Container-Read"` ContainerSyncTo string `h:"X-Container-Sync-To"` ContainerSyncKey string `h:"X-Container-Sync-Key"` ContainerWrite string `h:"X-Container-Write"` ContentType string `h:"Content-Type"` DetectContentType bool `h:"X-Detect-Content-Type"` IfNoneMatch string `h:"If-None-Match"` VersionsLocation string `h:"X-Versions-Location"` }
CreateOpts is a structure that holds parameters for creating a container.
func (CreateOpts) ToContainerCreateMap ¶
func (opts CreateOpts) ToContainerCreateMap() (map[string]string, error)
ToContainerCreateMap formats a CreateOpts into a map of headers.
type CreateOptsBuilder ¶
CreateOptsBuilder allows extensions to add additional parameters to the Create request.
type CreateResult ¶
type CreateResult struct {
gophercloud.HeaderResult
}
CreateResult represents the result of a create operation. To extract the the headers from the HTTP response, call its Extract method.
func Create ¶
func Create(c *gophercloud.ServiceClient, containerName string, opts CreateOptsBuilder) (r CreateResult)
Create is a function that creates a new container.
func (CreateResult) Extract ¶
func (r CreateResult) Extract() (*CreateHeader, error)
Extract will return a struct of headers returned from a call to Create. To extract the headers from the HTTP response, call its Extract method.
type DeleteHeader ¶
type DeleteHeader struct { ContentLength int64 `json:"-"` ContentType string `json:"Content-Type"` Date time.Time `json:"-"` TransID string `json:"X-Trans-Id"` }
DeleteHeader represents the headers returned in the response from a Delete request.
func (*DeleteHeader) UnmarshalJSON ¶
func (r *DeleteHeader) UnmarshalJSON(b []byte) error
type DeleteResult ¶
type DeleteResult struct {
gophercloud.HeaderResult
}
DeleteResult represents the result of a delete operation. To extract the the headers from the HTTP response, call its Extract method.
func Delete ¶
func Delete(c *gophercloud.ServiceClient, containerName string) (r DeleteResult)
Delete is a function that deletes a container.
func (DeleteResult) Extract ¶
func (r DeleteResult) Extract() (*DeleteHeader, error)
Extract will return a struct of headers returned from a call to Delete.
type GetHeader ¶
type GetHeader struct { AcceptRanges string `json:"Accept-Ranges"` BytesUsed int64 `json:"-"` ContentLength int64 `json:"-"` ContentType string `json:"Content-Type"` Date time.Time `json:"-"` ObjectCount int64 `json:"-"` Read []string `json:"-"` TransID string `json:"X-Trans-Id"` VersionsLocation string `json:"X-Versions-Location"` Write []string `json:"-"` StoragePolicy string `json:"X-Storage-Policy"` }
GetHeader represents the headers returned in the response from a Get request.
func (*GetHeader) UnmarshalJSON ¶
type GetResult ¶
type GetResult struct {
gophercloud.HeaderResult
}
GetResult represents the result of a get operation.
func Get ¶
func Get(c *gophercloud.ServiceClient, containerName string) (r GetResult)
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.
type ListOpts ¶
type ListOpts struct { Full bool Limit int `q:"limit"` Marker string `q:"marker"` EndMarker string `q:"end_marker"` Format string `q:"format"` Prefix string `q:"prefix"` Delimiter string `q:"delimiter"` }
ListOpts is a structure that holds options for listing containers.
type ListOptsBuilder ¶
ListOptsBuilder allows extensions to add additional parameters to the List request.
type UpdateHeader ¶
type UpdateHeader struct { ContentLength int64 `json:"-"` ContentType string `json:"Content-Type"` Date time.Time `json:"-"` TransID string `json:"X-Trans-Id"` }
UpdateHeader represents the headers returned in the response from a Update request.
func (*UpdateHeader) UnmarshalJSON ¶
func (r *UpdateHeader) UnmarshalJSON(b []byte) error
type UpdateOpts ¶
type UpdateOpts struct { Metadata map[string]string ContainerRead string `h:"X-Container-Read"` ContainerSyncTo string `h:"X-Container-Sync-To"` ContainerSyncKey string `h:"X-Container-Sync-Key"` ContainerWrite string `h:"X-Container-Write"` ContentType string `h:"Content-Type"` DetectContentType bool `h:"X-Detect-Content-Type"` RemoveVersionsLocation string `h:"X-Remove-Versions-Location"` VersionsLocation string `h:"X-Versions-Location"` }
UpdateOpts is a structure that holds parameters for updating, creating, or deleting a container's metadata.
func (UpdateOpts) ToContainerUpdateMap ¶
func (opts UpdateOpts) ToContainerUpdateMap() (map[string]string, error)
ToContainerUpdateMap formats a UpdateOpts into a map of headers.
type UpdateOptsBuilder ¶
UpdateOptsBuilder allows extensions to add additional parameters to the Update request.
type UpdateResult ¶
type UpdateResult struct {
gophercloud.HeaderResult
}
UpdateResult represents the result of an update operation. To extract the the headers from the HTTP response, call its Extract method.
func Update ¶
func Update(c *gophercloud.ServiceClient, containerName string, opts UpdateOptsBuilder) (r UpdateResult)
Update is a function that creates, updates, or deletes a container's metadata.
func (UpdateResult) Extract ¶
func (r UpdateResult) Extract() (*UpdateHeader, error)
Extract will return a struct of headers returned from a call to Update.