storage

package
v1.0.28 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 15 Imported by: ? 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

Vault — GoStack Path-Traversal Secure Storage Subsystem.

Naming Metaphor: Why Vault? The GoStack Storage Subsystem was named Vault because a bank "vault" is an impenetrable, reinforced safe that locks valuable assets behind strict security perimeters. Vault treats file uploads and disk writes like deposits into a reinforced chamber, strictly sanitizing and jailing file paths to completely shut down directory traversal attacks (`../../etc/passwd`).

Purpose: This file implements the LocalStorage driver for the Vault storage subsystem of GoStack. It provides a standard file-system storage backend complying with the Storage interface.

Philosophy: Storage engines must be unified and secure. Writing raw paths directly in application logic causes host platform locks. Additionally, un-sanitized user file path inputs expose applications to directory traversal exploits. This driver prevents that by resolving all operations strictly within a configured root directory.

Architecture: A standalone framework package (`github.com/charledeon77/gostack-framework/framework/storage`). Implements the `contract.Storage` interface.

Choice: We chose a local OS file-system backend using standard `os` and `filepath` primitives, ensuring zero-dependency footprint. The path resolution uses strict prefix checking against the root directory to guarantee sandbox safety.

Implementation: - LocalStorage: implements storage operations.

  • NewLocalStorage(rootDir): initializes and establishes root directory.
  • Put(): writes file content, creating missing subdirectories automatically.
  • Get(): reads file content.
  • Delete(): removes file.
  • Exists(): verifies file presence.
  • resolvePath(): sanitizes and validates bounds constraints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LocalStorage

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

LocalStorage handles file-system operations securely confined to a root path.

func NewLocalStorage

func NewLocalStorage(rootDir string) (*LocalStorage, error)

NewLocalStorage instantiates a LocalStorage driver bound to the specified root directory.

func (*LocalStorage) Delete

func (s *LocalStorage) Delete(path string) error

Delete removes the file at the relative target path.

func (*LocalStorage) Exists

func (s *LocalStorage) Exists(path string) (bool, error)

Exists reports whether the relative target path resolves to an existing file on disk. Returns (false, err) on a path-resolution or OS-level error (F-021, F-023).

func (*LocalStorage) Get

func (s *LocalStorage) Get(path string) ([]byte, error)

Get reads the file contents at the relative target path.

func (*LocalStorage) GetStream added in v1.0.23

func (s *LocalStorage) GetStream(path string) (io.ReadCloser, error)

GetStream opens the file at the relative target path and returns an io.ReadCloser stream. The caller is responsible for closing the returned reader when finished.

func (*LocalStorage) Put

func (s *LocalStorage) Put(path string, contents []byte) error

Put writes contents to the relative target path, creating parent folders if missing.

func (*LocalStorage) PutStream added in v1.0.23

func (s *LocalStorage) PutStream(path string, r io.Reader) error

PutStream writes content from the provided reader to the relative target path, creating parent folders if missing. Content is streamed with minimal RAM footprint.

type S3Config

type S3Config struct {
	Region          string
	Bucket          string
	Prefix          string // Optional path prefix for all keys
	AccessKeyID     string
	SecretAccessKey string
	Endpoint        string        // Optional: set for MinIO / Cloudflare R2
	Timeout         time.Duration // Optional: connection/request timeout (default: 30s)
}

S3Config holds the configuration parameters for an S3 connection.

type S3Driver

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

S3Driver implements contract.Storage backed by AWS S3 (or any S3-compatible endpoint).

func NewS3Driver

func NewS3Driver(cfg S3Config) (*S3Driver, error)

NewS3Driver creates a new S3Driver from the given configuration.

func (*S3Driver) Delete

func (s *S3Driver) Delete(path string) error

Delete removes the file at the given path from S3.

func (*S3Driver) Exists

func (s *S3Driver) Exists(path string) (bool, error)

Exists reports whether the given S3 key exists, using a cheap HeadObject call. Returns (false, err) on a driver or network error (F-021, F-023).

func (*S3Driver) Get

func (s *S3Driver) Get(path string) ([]byte, error)

Get downloads the file at the given path from S3 and returns its bytes. Enforces a 64MB read limit to prevent unbounded memory exhaustion (F-020).

func (*S3Driver) GetStream added in v1.0.23

func (s *S3Driver) GetStream(path string) (io.ReadCloser, error)

GetStream downloads the S3 object at the given path and returns its body as an io.ReadCloser stream. The caller is responsible for closing the returned stream.

func (*S3Driver) Put

func (s *S3Driver) Put(path string, contents []byte) error

Put uploads data bytes to S3 under the given path key.

func (*S3Driver) PutStream added in v1.0.23

func (s *S3Driver) PutStream(path string, r io.Reader) error

PutStream streams content from an io.Reader to S3 under the given path key. The stream is passed directly to the S3 PutObject API without buffering into server RAM.

Jump to

Keyboard shortcuts

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