Help us shape the future of Go! Take the 2026 Go Developer Survey

storage

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0, MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeFilesystem = "filesystem"
	TypeS3         = "s3"
)

Backend type names.

View Source
const DefaultProfilePicture = "default-profile-picture"

DefaultProfilePicture is the bundled fallback image served when a user has no custom profile picture.

Variables

View Source
var ErrNotFound = errors.New("storage: object not found")

ErrNotFound reports a missing object.

Functions

func IsNotExist

func IsNotExist(err error) bool

IsNotExist reports whether err came from a missing object.

Types

type BundledImages

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

BundledImages is the read-only view of images seeded from the frontend asset bundle into the blob store.

func SeedBundledImages

func SeedBundledImages(ctx context.Context, store Store, sourceDir string) (*BundledImages, error)

SeedBundledImages copies bundled images from sourceDir into the blob store and returns the seeded set. A missing sourceDir (fresh checkouts, tests) seeds nothing.

func (*BundledImages) Open

func (b *BundledImages) Open(ctx context.Context, name string) (io.ReadCloser, int64, string, bool)

Open returns the bundled image bytes, size, and MIME type; ok=false when the image is not seeded.

type ObjectInfo

type ObjectInfo struct {
	Path    string
	Size    int64
	ModTime os.FileInfo // nil for S3 listings without the field
}

ObjectInfo describes one stored object in a List result.

type S3Config

type S3Config struct {
	Bucket          string
	Region          string
	Endpoint        string
	AccessKeyID     string
	SecretAccessKey string
	ForcePathStyle  bool
	Root            string
}

S3Config selects the bucket, endpoint, and credentials.

type Store

type Store interface {
	Save(ctx context.Context, path string, data io.Reader) error
	Open(ctx context.Context, path string) (io.ReadCloser, int64, error)
	Delete(ctx context.Context, path string) error
	DeleteAll(ctx context.Context, prefix string) error
	List(ctx context.Context, prefix string) ([]ObjectInfo, error)
	Type() string
}

Store is the blob backend contract. Paths are root-relative and use slashes.

func New

func New(cfg config.StorageConfig) (Store, error)

New selects S3 when an endpoint is set, otherwise filesystem storage.

func NewFilesystemStorage

func NewFilesystemStorage(rootPath string) (Store, error)

NewFilesystemStorage builds a filesystem backend rooted at rootPath.

func NewS3Storage

func NewS3Storage(cfg S3Config) (Store, error)

NewS3Storage builds an S3 backend with static credentials.

Jump to

Keyboard shortcuts

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