containers

package
v0.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

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

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",
	},
}

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

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 *golangsdk.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

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

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

type CreateResult

type CreateResult struct {
	golangsdk.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 *golangsdk.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 {
	golangsdk.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 *golangsdk.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

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

type GetOpts

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

GetOpts is a structure that holds options for listing containers.

func (GetOpts) ToContainerGetMap

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

ToContainerGetMap formats a GetOpts into a map of headers.

type GetOptsBuilder

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

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

type GetResult

type GetResult struct {
	golangsdk.HeaderResult
}

GetResult represents the result of a get operation.

func Get

func Get(c *golangsdk.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

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

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

func (GetResult) ExtractMetadata

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

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

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

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

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

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

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

type UpdateResult

type UpdateResult struct {
	golangsdk.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 *golangsdk.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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL