gophercloud: github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers Index | Files | Directories

package containers

import "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers"

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).

Note: When referencing the Object Storage API docs, some of the API actions are listed under "accounts" rather than "containers". This was an intentional design in Gophercloud to make some container actions feel more natural.

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",
	},
	RemoveMetadata: []string{
		"foo",
	},
}

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

Package Files

doc.go requests.go results.go urls.go

func ExtractNames Uses

func ExtractNames(page pagination.Page) ([]string, error)

ExtractNames is a function that takes a ListResult and returns the containers' names.

func List Uses

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.

type Container Uses

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 Uses

func ExtractInfo(r pagination.Page) ([]Container, error)

ExtractInfo is a function that takes a ListResult and returns the containers' information.

type ContainerPage Uses

type ContainerPage struct {
    pagination.MarkerPageBase
}

ContainerPage is the page returned by a pager when traversing over a collection of containers.

func (ContainerPage) IsEmpty Uses

func (r ContainerPage) IsEmpty() (bool, error)

IsEmpty returns true if a ListResult contains no container names.

func (ContainerPage) LastMarker Uses

func (r ContainerPage) LastMarker() (string, error)

LastMarker returns the last container name in a ListResult.

type CreateHeader Uses

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 Uses

func (r *CreateHeader) UnmarshalJSON(b []byte) error

type CreateOpts Uses

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"`
    HistoryLocation   string `h:"X-History-Location"`
}

CreateOpts is a structure that holds parameters for creating a container.

func (CreateOpts) ToContainerCreateMap Uses

func (opts CreateOpts) ToContainerCreateMap() (map[string]string, error)

ToContainerCreateMap formats a CreateOpts into a map of headers.

type CreateOptsBuilder Uses

type CreateOptsBuilder interface {
    ToContainerCreateMap() (map[string]string, error)
}

CreateOptsBuilder allows extensions to add additional parameters to the Create request.

type CreateResult Uses

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 Uses

func Create(c *gophercloud.ServiceClient, containerName string, opts CreateOptsBuilder) (r CreateResult)

Create is a function that creates a new container.

func (CreateResult) Extract Uses

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 Uses

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 Uses

func (r *DeleteHeader) UnmarshalJSON(b []byte) error

type DeleteResult Uses

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 Uses

func Delete(c *gophercloud.ServiceClient, containerName string) (r DeleteResult)

Delete is a function that deletes a container.

func (DeleteResult) Extract Uses

func (r DeleteResult) Extract() (*DeleteHeader, error)

Extract will return a struct of headers returned from a call to Delete.

type GetHeader Uses

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"`
    HistoryLocation  string    `json:"X-History-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 Uses

func (r *GetHeader) UnmarshalJSON(b []byte) error

type GetOpts Uses

type GetOpts struct {
    Newest bool `h:"X-Newest"`
}

GetOpts is a structure that holds options for listing containers.

func (GetOpts) ToContainerGetMap Uses

func (opts GetOpts) ToContainerGetMap() (map[string]string, error)

ToContainerGetMap formats a GetOpts into a map of headers.

type GetOptsBuilder Uses

type GetOptsBuilder interface {
    ToContainerGetMap() (map[string]string, error)
}

GetOptsBuilder allows extensions to add additional parameters to the Get request.

type GetResult Uses

type GetResult struct {
    gophercloud.HeaderResult
}

GetResult represents the result of a get operation.

func Get Uses

func Get(c *gophercloud.ServiceClient, containerName string, opts GetOptsBuilder) (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.

func (GetResult) Extract Uses

func (r GetResult) Extract() (*GetHeader, error)

Extract will return a struct of headers returned from a call to Get.

func (GetResult) ExtractMetadata Uses

func (r GetResult) ExtractMetadata() (map[string]string, error)

ExtractMetadata is a function that takes a GetResult (of type *http.Response) and returns the custom metadata associated with the container.

type ListOpts Uses

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.

func (ListOpts) ToContainerListParams Uses

func (opts ListOpts) ToContainerListParams() (bool, string, error)

ToContainerListParams formats a ListOpts into a query string and boolean representing whether to list complete information for each container.

type ListOptsBuilder Uses

type ListOptsBuilder interface {
    ToContainerListParams() (bool, string, error)
}

ListOptsBuilder allows extensions to add additional parameters to the List request.

type UpdateHeader Uses

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 Uses

func (r *UpdateHeader) UnmarshalJSON(b []byte) error

type UpdateOpts Uses

type UpdateOpts struct {
    Metadata               map[string]string
    RemoveMetadata         []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"`
    RemoveHistoryLocation  string `h:"X-Remove-History-Location"`
    HistoryLocation        string `h:"X-History-Location"`
}

UpdateOpts is a structure that holds parameters for updating, creating, or deleting a container's metadata.

func (UpdateOpts) ToContainerUpdateMap Uses

func (opts UpdateOpts) ToContainerUpdateMap() (map[string]string, error)

ToContainerUpdateMap formats a UpdateOpts into a map of headers.

type UpdateOptsBuilder Uses

type UpdateOptsBuilder interface {
    ToContainerUpdateMap() (map[string]string, error)
}

UpdateOptsBuilder allows extensions to add additional parameters to the Update request.

type UpdateResult Uses

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 Uses

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 Uses

func (r UpdateResult) Extract() (*UpdateHeader, error)

Extract will return a struct of headers returned from a call to Update.

Directories

PathSynopsis
testingcontainers unit tests

Package containers imports 7 packages (graph) and is imported by 80 packages. Updated 2019-07-31. Refresh now. Tools for package owners.