storage

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileNotFound = errors.New("storage: file not found")
	ErrInvalidPath  = errors.New("storage: invalid path")
)

Functions

This section is empty.

Types

type LocalDriver

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

LocalDriver 本地存储驱动

func NewLocalDriver

func NewLocalDriver(root string, baseURL string) *LocalDriver

NewLocalDriver 创建本地驱动

func (*LocalDriver) Delete

func (d *LocalDriver) Delete(path string) error

Delete 删除文件

func (*LocalDriver) Exists

func (d *LocalDriver) Exists(path string) bool

Exists 检查文件是否存在

func (*LocalDriver) Get

func (d *LocalDriver) Get(path string) ([]byte, error)

Get 获取文件内容

func (*LocalDriver) Put

func (d *LocalDriver) Put(path string, content []byte) error

Put 存储文件

func (*LocalDriver) PutFile

func (d *LocalDriver) PutFile(path string, reader io.Reader) error

PutFile 从 Reader 存储文件

func (*LocalDriver) Size

func (d *LocalDriver) Size(path string) (int64, error)

Size 获取文件大小

func (*LocalDriver) URL

func (d *LocalDriver) URL(path string) string

URL 获取文件URL

type Manager

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

Manager 存储管理器

func NewManager

func NewManager() *Manager

NewManager 创建存储管理器

func (*Manager) AddDriver

func (m *Manager) AddDriver(name string, driver Storage)

AddDriver 添加存储驱动

func (*Manager) Driver

func (m *Manager) Driver(name string) Storage

Driver 获取指定驱动

func (*Manager) Get

func (m *Manager) Get(path string) ([]byte, error)

Get 使用默认驱动获取文件

func (*Manager) Put

func (m *Manager) Put(path string, content []byte) error

Put 使用默认驱动存储文件

func (*Manager) SetDefault

func (m *Manager) SetDefault(name string)

SetDefault 设置默认驱动

type Storage

type Storage interface {
	// Put 存储文件
	Put(path string, content []byte) error

	// PutFile 存储文件(从 Reader)
	PutFile(path string, reader io.Reader) error

	// Get 获取文件内容
	Get(path string) ([]byte, error)

	// Exists 检查文件是否存在
	Exists(path string) bool

	// Delete 删除文件
	Delete(path string) error

	// URL 获取文件访问 URL
	URL(path string) string

	// Size 获取文件大小
	Size(path string) (int64, error)
}

Storage 存储接口

Jump to

Keyboard shortcuts

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