storage

package
v0.12.12 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 12 Imported by: 0

README

Storage Package

The storage package provides unified filesystem abstraction with support for multiple storage backends.

Features

  • Multi-Backend Support: Local FS, OSS, SFTP
  • Afero Integration: Built on Afero filesystem abstraction
  • Named Filesystems: Register and retrieve filesystems by name
  • Caching: Optional filesystem caching
  • Directory Management: Create and manage directories

Main Components

Filesystem Service
  • GetFs(key): Get filesystem by key
  • CreateFs(key): Create filesystem with release function
  • EnsureDir(fs, dir): Create directory if not exists
Storage Backends
  • Local: Local filesystem access
  • OSS: Alibaba Cloud Object Storage Service
  • SFTP: SSH File Transfer Protocol
OssSettings

Configuration for OSS:

  • Endpoint: OSS endpoint URL
  • AccessKey: Access key ID
  • SecretKey: Access key secret
  • Bucket: Bucket name
  • Region: OSS region
  • Path: Base path prefix

Usage

// Get filesystem
fs, release, err := storage.CreateFs("oss")
if err != nil {
    return err
}
defer release()

// Write file
err = afero.WriteFile(fs, "path/to/file.txt", data, 0644)

// Create directory
err = storage.EnsureDir(fs, "path/to/dir")

Configuration

Configure storage backends via Viper:

oss:
  endpoint: https://oss-cn-hangzhou.aliyuncs.com
  accessKey: your-access-key
  secretKey: your-secret-key
  bucket: my-bucket
  region: cn-hangzhou
  path: /app/data

Dependencies

  • Afero for filesystem abstraction
  • FS-OSS for OSS integration
  • Viper for configuration
  • Zap for logging

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NamedFsService = map[string]InitFs{}
	FsCacheEnabled = map[string]bool{
		"":      true,
		"local": true,
	}
)

Functions

func EnsureDir added in v0.11.9

func EnsureDir(fs afero.Fs, dir string) error

Types

type InitFs

type InitFs func(key string) (afero.Fs, Release, error)

type OssSettings added in v0.11.9

type OssSettings struct {
	Endpoint  string
	AccessKey string
	SecretKey string
	Bucket    string
	Region    string
	Path      string
}

type Release

type Release func()

func CreateFs

func CreateFs(key string) (afero.Fs, Release, error)

func InitSftpRoot added in v0.11.9

func InitSftpRoot(key string) (afero.Fs, Release, error)

type SftpSettings added in v0.11.9

type SftpSettings struct {
	Endpoint       string
	Account        string
	Password       string
	PrivateKeypath string
	Path           string
}

Jump to

Keyboard shortcuts

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