{"modulePath":"github.com/jdostech/gophercloud","version":"v1.0.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package gophercloud\n\nPackage gophercloud provides a multi-vendor interface to OpenStack-compatible clouds. The library has a three-level hierarchy: providers, services, and resources.\n\nProvider structs represent the service providers that offer and manage a collection of services. Examples of providers include: OpenStack, Rackspace, HP. These are defined like so:\n\n\topts := gophercloud.AuthOptions{\n\t  IdentityEndpoint: \"https://my-openstack.com:5000/v2.0\",\n\t  Username: \"{username}\",\n\t  Password: \"{password}\",\n\t  TenantID: \"{tenant_id}\",\n\t}\n\n\tprovider, err := openstack.AuthenticatedClient(opts)\n\nService structs are specific to a provider and handle all of the logic and operations for a particular OpenStack service. Examples of services include: Compute, Object Storage, Block Storage. In order to define one, you need to pass in the parent provider, like so:\n\n\topts := gophercloud.EndpointOpts{Region: \"RegionOne\"}\n\n\tclient := openstack.NewComputeV2(provider, opts)\n\nResource structs are the domain models that services make use of in order to work with and represent the state of API resources:\n\n\tserver, err := servers.Get(client, \"{serverId}\").Extract()\n\nAnother convention is to return Result structs for API operations, which allow you to access the HTTP headers, response body, and associated errors with the network transaction. To get a resource struct, you then call the Extract method which is chained to the response.\n\n## Constants\n\n```go\nconst RFC3339Milli = \"2006-01-02T15:04:05.999999Z\"\n```\nRFC3339Milli describes a time format used by API responses.\n\n## Variables\n\n```go\nvar (\n\t// ErrServiceNotFound is returned when no service matches the EndpointOpts.\n\tErrServiceNotFound = errors.New(\"No suitable service could be found in the service catalog.\")\n\n\t// ErrEndpointNotFound is returned when no available endpoints match the provided EndpointOpts.\n\tErrEndpointNotFound = errors.New(\"No suitable endpoint could be found in the service catalog.\")\n)\n```\n\n## Functions\n\n```go\nfunc BuildHeaders(opts interface{}) (map[string]string, error)\n```\nBuildHeaders accepts a generic structure and parses it into a string map. It converts field names into header names based on \"h\" tags, and field values into header values by a simple one-to-one mapping.\n\n```go\nfunc BuildQueryString(opts interface{}) (*url.URL, error)\n```\nBuildQueryString accepts a generic structure and parses it URL struct. It converts field names into query names based on \"q\" tags. So for example, this type:\n\n\tstruct {\n\t   Bar string `q:\"x_bar\"`\n\t   Baz int    `q:\"lorem_ipsum\"`\n\t}{\n\t   Bar: \"XXX\",\n\t   Baz: \"YYY\",\n\t}\n\nwill be converted into ?x\\_bar=XXX\u0026lorem\\_ipsum=YYYY\n\n```go\nfunc ExtractNextURL(links []Link) (string, error)\n```\nExtractNextURL attempts to extract the next URL from a JSON structure. It follows the common convention of nesting back and next URLs in a \"links\" JSON array.\n\n```go\nfunc MaybeInt(original int) *int\n```\nMaybeInt takes an int that might be a zero-value, and either returns a pointer to its address or a nil value (i.e. empty pointer).\n\n```go\nfunc MaybeString(original string) *string\n```\nMaybeString takes a string that might be a zero-value, and either returns a pointer to its address or a nil value (i.e. empty pointer). This is useful for converting zero values in options structs when the end-user hasn't defined values. Those zero values need to be nil in order for the JSON serialization to ignore them.\n\n```go\nfunc NormalizeURL(url string) string\n```\nNormalizeURL ensures that each endpoint URL has a closing \\`/\\`, as expected by ServiceClient.\n\n```go\nfunc WaitFor(timeout int, predicate func() (bool, error)) error\n```\nWaitFor polls a predicate function, once per second, up to a timeout limit. It usually does this to wait for the resource to transition to a certain state.\n\n## Types\n\n```go\ntype AuthOptions struct {\n\t// IdentityEndpoint specifies the HTTP endpoint that is required to work with\n\t// the Identity API of the appropriate version. Required by the identity\n\t// services, but often populated by a provider Client.\n\tIdentityEndpoint string\n\n\t// Username is required if using Identity V2 API. Consult with your provider's\n\t// control panel to discover your account's username. In Identity V3, either\n\t// UserID or a combination of Username and DomainID or DomainName.\n\tUsername, UserID string\n\n\t// Exactly one of Password or ApiKey is required for the Identity V2 and V3\n\t// APIs. Consult with your provider's control panel to discover your account's\n\t// preferred method of authentication.\n\tPassword, APIKey string\n\n\t// At most one of DomainID and DomainName must be provided if using Username\n\t// with Identity V3. Otherwise, either are optional.\n\tDomainID, DomainName string\n\n\t// The TenantID and TenantName fields are optional for the Identity V2 API.\n\t// Some providers allow you to specify a TenantName instead of the TenantId.\n\t// Some require both.  Your provider's authentication policies will determine\n\t// how these fields influence authentication.\n\tTenantID, TenantName string\n\n\t// AllowReauth should be set to true if you grant permission for Gophercloud to\n\t// cache your credentials in memory, and to allow Gophercloud to attempt to\n\t// re-authenticate automatically if/when your token expires.  If you set it to\n\t// false, it will not cache these settings, but re-authentication will not be\n\t// possible.  This setting defaults to false.\n\tAllowReauth bool\n}\n```\nAuthOptions allows anyone calling Authenticate to supply the required access credentials. Its fields are the union of those recognized by each identity implementation and provider.\n\n```go\ntype AuthResults interface {\n\t// TokenID returns the token's ID value from the authentication response.\n\tTokenID() (string, error)\n\n\t// ExpiresAt retrieves the token's expiration time.\n\tExpiresAt() (time.Time, error)\n}\n```\nAuthResults encapsulates the raw results from an authentication request. As OpenStack allows extensions to influence the structure returned in ways that Gophercloud cannot predict at compile-time, you should use type-safe accessors to work with the data represented by this type, such as ServiceCatalog and TokenID.\n\n```go\ntype Availability string\n```\nAvailability indicates whether a specific service endpoint is accessible. Identity v2 lists these as different kinds of URLs (\"adminURL\", \"internalURL\", and \"publicURL\"), while v3 lists them as \"Interfaces\".\n\n```go\nconst (\n\t// AvailabilityAdmin makes an endpoint only available to administrators.\n\tAvailabilityAdmin Availability = \"admin\"\n\n\t// AvailabilityPublic makes an endpoint available to everyone.\n\tAvailabilityPublic Availability = \"public\"\n\n\t// AvailabilityInternal makes an endpoint only available within the cluster.\n\tAvailabilityInternal Availability = \"internal\"\n)\n```\n\n```go\ntype EndpointLocator func(EndpointOpts) (string, error)\n```\nEndpointLocator is a function that describes how to locate a single endpoint from a service catalog for a specific ProviderClient. It should be set during ProviderClient authentication and used to discover related ServiceClients.\n\n```go\ntype EndpointOpts struct {\n\t// Type is the service type for the client (e.g., \"compute\", \"object-store\").\n\t// Required.\n\tType string\n\n\t// Name is the service name for the client (e.g., \"nova\") as it appears in\n\t// the service catalog. Services can have the same Type but a different Name,\n\t// which is why both Type and Name are sometimes needed. Optional.\n\tName string\n\n\t// Region is the geographic region in which the service resides. Required only\n\t// for services that span multiple regions.\n\tRegion string\n\n\t// Availability is the visibility of the endpoint to be returned. Valid types\n\t// are: AvailabilityPublic, AvailabilityInternal, or AvailabilityAdmin.\n\t// Availability is not required, and defaults to AvailabilityPublic.\n\t// Not all providers or services offer all Availability options.\n\tAvailability Availability\n}\n```\nEndpointOpts contains options for finding an endpoint for an Openstack client.\n\n```go\nfunc (eo *EndpointOpts) ApplyDefaults(t string)\n```\nApplyDefaults sets EndpointOpts fields if not already set. Currently, EndpointOpts.Availability defaults to the public endpoint.\n\n```go\ntype ErrResult struct {\n\tResult\n}\n```\nErrResult represents results that only contain a potential error and nothing else. Usually if the operation executed successfully, the Err field will be nil; otherwise it will be stocked with a relevant error.\n\n```go\nfunc (r ErrResult) ExtractErr() error\n```\nExtractErr is a function that extracts error information from a result.\n\n```go\ntype HeaderResult struct {\n\tResult\n}\n```\nHeaderResult represents a result that only contains an \\`error\\` (possibly nil) and an http.Header. This is used, for example, by the \\`objectstorage\\` packages in \\`openstack\\`, because most of the operations don't return response bodies.\n\n```go\nfunc (hr HeaderResult) ExtractHeader() (http.Header, error)\n```\nExtractHeader will return the http.Header and error from the HeaderResult. Usage: header, err := objects.Create(client, \"my\\_container\", objects.CreateOpts{}).ExtractHeader()\n\n```go\ntype Link struct {\n\tHref string `mapstructure:\"href\"`\n\tRel  string `mapstructure:\"rel\"`\n}\n```\nLink represents a structure that enables paginated collections how to traverse backward or forward. The \"Rel\" field is usually either \"next\".\n\n```go\ntype ProviderClient struct {\n\t// IdentityBase is the base URL used for a particular provider's identity\n\t// service - it will be used when issuing authenticatation requests. It\n\t// should point to the root resource of the identity service, not a specific\n\t// identity version.\n\tIdentityBase string\n\n\t// IdentityEndpoint is the identity endpoint. This may be a specific version\n\t// of the identity service. If this is the case, this endpoint is used rather\n\t// than querying versions first.\n\tIdentityEndpoint string\n\n\t// TokenID is the ID of the most recently issued valid token.\n\tTokenID string\n\n\t// EndpointLocator describes how this provider discovers the endpoints for\n\t// its constituent services.\n\tEndpointLocator EndpointLocator\n}\n```\nProviderClient stores details that are required to interact with any services within a specific provider's API.\n\nGenerally, you acquire a ProviderClient by calling the NewClient method in the appropriate provider's child package, providing whatever authentication credentials are required.\n\n```go\nfunc (client *ProviderClient) AuthenticatedHeaders() map[string]string\n```\nAuthenticatedHeaders returns a map of HTTP headers that are common for all authenticated service requests.\n\n```go\ntype Result struct {\n\t// Body is the payload of the HTTP response from the server. In most cases, this will be the\n\t// deserialized JSON structure.\n\tBody interface{}\n\n\t// Header contains the HTTP header structure from the original response.\n\tHeader http.Header\n\n\t// Err is an error that occurred during the operation. It's deferred until extraction to make\n\t// it easier to chain operations.\n\tErr error\n}\n```\nResult acts as a base struct that other results can embed.\n\n```go\nfunc (r Result) PrettyPrintJSON() string\n```\nPrettyPrintJSON creates a string containing the full response body as pretty-printed JSON.\n\n```go\ntype ServiceClient struct {\n\t// ProviderClient is a reference to the provider that implements this service.\n\t*ProviderClient\n\n\t// Endpoint is the base URL of the service's API, acquired from a service catalog.\n\t// It MUST end with a /.\n\tEndpoint string\n\n\t// ResourceBase is the base URL shared by the resources within a service's API. It should include\n\t// the API version and, like Endpoint, MUST end with a / if set. If not set, the Endpoint is used\n\t// as-is, instead.\n\tResourceBase string\n}\n```\nServiceClient stores details required to interact with a specific service API implemented by a provider. Generally, you'll acquire these by calling the appropriate \\`New\\` method on a ProviderClient.\n\n```go\nfunc (client *ServiceClient) ResourceBaseURL() string\n```\nResourceBaseURL returns the base URL of any resources used by this service. It MUST end with a /.\n\n```go\nfunc (client *ServiceClient) ServiceURL(parts ...string) string\n```\nServiceURL constructs a URL for a resource belonging to this provider.\n\n","path":"github.com/jdostech/gophercloud","name":"gophercloud","synopsis":"Package gophercloud provides a multi-vendor interface to OpenStack-compatible clouds.","isRedistributable":true}
