Documentation ¶
Overview ¶
Package gcp provides a storage driver to upload module files to a google cloud platform storage bucket.
Configuration ¶
Environment variables:
ATHENS_STORAGE_GCP_BUCKET // full name of storage bucket ATHENS_STORAGE_GCP_SA // path to json keyfile of a service account
Example:
Bash: export ATHENS_STORAGE_GCP_BUCKET="fancy-pony-33928.appspot.com" Fish: set -x ATHENS_STORAGE_GCP_BUCKET fancy-pony-339288.appspot.com
Index ¶
- type Bucket
- type Storage
- func (s *Storage) BaseURL() *url.URL
- func (s *Storage) Close() error
- func (s *Storage) Delete(ctx context.Context, module, version string) error
- func (s *Storage) Exists(ctx context.Context, module, version string) bool
- func (s *Storage) Get(ctx context.Context, module, version string) (*storage.Version, error)
- func (s *Storage) List(ctx context.Context, module string) ([]string, error)
- func (s *Storage) Save(ctx context.Context, module, version string, mod []byte, zip io.Reader, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket interface { // Delete removes the file Delete(ctx context.Context, path string) error // Open returns a reader for a path and any error Open(ctx context.Context, path string) (io.ReadCloser, error) // Write returns a new writer for a path // This writer will overwrite any existing file stored at the same path Write(ctx context.Context, path string) io.WriteCloser // List returns a slice of paths for a prefix and any error List(ctx context.Context, prefix string) ([]string, error) // Exists returns true if the file exists Exists(ctx context.Context, path string) bool }
Bucket provides file operations for a Google Cloud Storage resource.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage implements the (./pkg/storage).Backend interface
func NewWithCredentials ¶
NewWithCredentials returns a new Storage instance authenticated using the provided ClientOptions. The bucket name to be used will be loaded from the environment variable ATHENS_STORAGE_GCP_BUCKET.
The ClientOptions should provide permissions sufficient to read, write and delete objects in google cloud storage for your project.
func (*Storage) BaseURL ¶
BaseURL returns the base URL that stores all modules. It can be used in the "meta" tag redirect response to vgo.
For example:
<meta name="go-import" content="gomods.com/athens mod BaseURL()">
func (*Storage) Close ¶
Close calls the underlying storage client's close method It is not required to be called on program exit but provided here for completness.
func (*Storage) Delete ¶
Delete implements the (./pkg/storage).Deleter interface and removes a version of a module from storage. Returning ErrNotFound if the version does not exist.
func (*Storage) Exists ¶
Exists implements the (./pkg/storage).Checker interface returning true if the module at version exists in storage
func (*Storage) Get ¶
Get retrieves a module at a specific version from storage as a (./pkg/storage).Version
The caller is responsible for calling close on the Zip ReadCloser
func (*Storage) List ¶
List implements the (./pkg/storage).Lister interface It returns a list of versions, if any, for a given module
func (*Storage) Save ¶
func (s *Storage) Save(ctx context.Context, module, version string, mod []byte, zip io.Reader, info []byte) error
Save uploads the module's .mod, .zip and .info files for a given version It expects a context, which can be provided using context.Background from the standard library until context has been threaded down the stack. see issue: https://github.com/gomods/athens/issues/174
Uploaded files are publicly accessable in the storage bucket as per an ACL rule.