containers

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: Apache-2.0 Imports: 6 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",
	},
	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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckContainerName

func CheckContainerName(s string) error

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 BulkDeleteResponse

type BulkDeleteResponse struct {
	ResponseStatus string     `json:"Response Status"`
	ResponseBody   string     `json:"Response Body"`
	Errors         [][]string `json:"Errors"`
	NumberDeleted  int        `json:"Number Deleted"`
	NumberNotFound int        `json:"Number Not Found"`
}

type BulkDeleteResult

type BulkDeleteResult struct {
	gophercloud.Result
}

BulkDeleteResult represents the result of a bulk delete operation. To extract the response object from the HTTP response, call its Extract method.

func BulkDelete

func BulkDelete(c *gophercloud.ServiceClient, containers []string) (r BulkDeleteResult)

BulkDelete is a function that bulk deletes containers.

func (BulkDeleteResult) Extract

func (r BulkDeleteResult) Extract() (*BulkDeleteResponse, error)

Extract will return a BulkDeleteResponse struct returned from a BulkDelete call.

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:"Content-Length,string"`
	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"`
	HistoryLocation   string `h:"X-History-Location"`
	TempURLKey        string `h:"X-Container-Meta-Temp-URL-Key"`
	TempURLKey2       string `h:"X-Container-Meta-Temp-URL-Key-2"`
	StoragePolicy     string `h:"X-Storage-Policy"`
}

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 {
	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:"Content-Length,string"`
	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 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 ErrInvalidContainerName

type ErrInvalidContainerName struct {
	gophercloud.BaseError
}

ErrInvalidContainerName signals a container name containing an illegal character.

func (ErrInvalidContainerName) Error

func (e ErrInvalidContainerName) Error() string

type GetHeader

type GetHeader struct {
	AcceptRanges     string    `json:"Accept-Ranges"`
	BytesUsed        int64     `json:"X-Container-Bytes-Used,string"`
	ContentLength    int64     `json:"Content-Length,string"`
	ContentType      string    `json:"Content-Type"`
	Date             time.Time `json:"-"`
	ObjectCount      int64     `json:"X-Container-Object-Count,string"`
	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"`
	TempURLKey       string    `json:"X-Container-Meta-Temp-URL-Key"`
	TempURLKey2      string    `json:"X-Container-Meta-Temp-URL-Key-2"`
	Timestamp        float64   `json:"X-Timestamp,string"`
}

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 {
	gophercloud.HeaderResult
}

GetResult represents the result of a get operation.

func Get

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

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:"Content-Length,string"`
	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
	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"`
	TempURLKey             string  `h:"X-Container-Meta-Temp-URL-Key"`
	TempURLKey2            string  `h:"X-Container-Meta-Temp-URL-Key-2"`
}

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

Directories

Path Synopsis
containers unit tests
containers unit tests

Jump to

Keyboard shortcuts

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