local

package
v0.5.13 Latest Latest
Warning

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

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

Documentation

Overview

Package local keeps objects in a directory under the project, which is the backend api:cli-dev and a test run on: a developer loop that needs an S3 endpoint before a file can be stored is one nobody starts with.

import _ "github.com/shibukawa/popcornweb/storage/local"

Each object is one file under the directory, with a sidecar carrying the media type and user metadata a file system does not keep.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	// contains filtered or unexported fields
}

Bucket is one directory of objects.

func New

func New(name, directory string) (*Bucket, error)

New opens a directory as a bucket named name, for a caller building one outside the configuration, such as a test.

func (*Bucket) Delete

func (b *Bucket) Delete(ctx context.Context, key string) error

Delete removes one object; a missing key is not an error.

func (*Bucket) Get

func (b *Bucket) Get(ctx context.Context, key string) (*storage.Object, error)

Get opens one object.

func (*Bucket) Head

func (b *Bucket) Head(ctx context.Context, key string) (*storage.ObjectInfo, error)

Head reports one object's metadata.

func (*Bucket) List

func (b *Bucket) List(ctx context.Context, options storage.ListOptions) (*storage.ListPage, error)

List walks the directory in key order. The cursor is the last key of the previous page, so a page after a deletion still continues.

func (*Bucket) Presign

func (b *Bucket) Presign(ctx context.Context, key string, options storage.PresignOptions) (*url.URL, error)

Presign returns a path under storage.SignedPathPrefix that the application serves itself, signed with a key this process generated when the bucket opened. The URL is relative: the page that hands it to a browser is on the same origin, and the backend does not know the host it is served on. It lives for options.Expires, or storage.DefaultPresignExpiry, and dies with the process, which is what a development loop wants.

func (*Bucket) Put

func (b *Bucket) Put(ctx context.Context, key string, body io.Reader, options storage.PutOptions) error

Put writes one object and its sidecar. The bytes land under a temporary name and are renamed into place, so a reader never sees a half-written object.

func (*Bucket) VerifySignedRequest

func (b *Bucket) VerifySignedRequest(r *http.Request, key string) (string, error)

VerifySignedRequest is the storage.SelfServing half of Presign: the signature covers the method, the key and the expiry, so a URL signed for a GET does not authorize a PUT and one past its expiry authorizes nothing.

Jump to

Keyboard shortcuts

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