storage

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package storage reads and writes the objects in an app's buckets, with the app's own S3 credentials (the Secret maxcloud-s3 the controller keeps in its namespace).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base

func Base(key string) string

Base is the last part of a key: the file name it downloads to.

Types

type Client

type Client struct {
	// App is the app's name; its buckets are mc-<app>--<name>.
	App string
	// contains filtered or unexported fields
}

Client is an S3 client for one app's buckets.

func New

func New(app string, secret map[string]string) (*Client, error)

New makes a client from the app's maxcloud-s3 Secret (the AWS_* variables its functions get).

func (*Client) Bucket

func (c *Client) Bucket(name string) string

Bucket is a bucket's full name in Object Storage: mc-<app>--<name>.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, name string, keys []string) error

Delete removes the objects at keys, 1000 a request.

func (*Client) Download

func (c *Client) Download(ctx context.Context, name, key, file string, w io.Writer) (int64, error)

Download writes the object at key to a local file (through a temporary file next to it, so a failed download leaves nothing half-written), or to w if file is "".

func (*Client) List

func (c *Client) List(ctx context.Context, name, prefix string, recursive bool, fn func(Object) error) error

List calls fn for every object under prefix in the bucket, in key order. Without recursive it stops at the next "/": deeper keys come once, as a folder (an Object whose Key ends in "/", with no size).

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, name, key, file string) (int64, error)

Upload puts a local file at key. The content type comes from the file's extension, as a browser fetching it from a public bucket expects.

type Object

type Object struct {
	Key      string
	Size     int64
	Modified time.Time
}

Object is one object in a bucket.

type Ref

type Ref struct {
	Bucket, Key string
}

Ref is a bucket and a key (or key prefix) in it: "uploads:img/a.png".

func ParseRef

func ParseRef(s string) (ref Ref, ok bool)

ParseRef splits BUCKET:KEY. ok is false for anything that isn't a bucket reference: a local path. A bucket's name is lowercase letters, digits and dashes, so "./a:b", "C:\x" and "/tmp/a:b" stay local.

func (Ref) Join

func (r Ref) Join(rel string) string

Join is the key of a file named rel (slash-separated) under r: a key that is empty or ends in "/" is a folder.

func (Ref) String

func (r Ref) String() string

Jump to

Keyboard shortcuts

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