storage

package module
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 14 Imported by: 4

README

storage

storage 是 infrago 的模块

包定位

  • 类型:模块
  • 作用:对象存储模块,负责上传下载、URL 签名、元数据处理。

主要功能

  • 对上提供统一模块接口
  • 对下通过驱动接口接入具体后端
  • 支持按配置切换驱动实现

快速接入

import _ "github.com/infrago/storage"
[storage]
driver = "default"

驱动实现接口列表

以下接口由驱动实现(来自模块 driver.go):

Driver
  • Connect(*Instance) (Connection, error)
Stream
  • io.Reader
  • io.Seeker
  • io.Closer
  • io.ReaderAt
Connection
  • Open() error
  • Health() Health
  • Close() error
  • Upload(string, UploadOption) (*File, error)
  • Fetch(*File, FetchOption) (Stream, error)
  • Download(*File, DownloadOption) (string, error)
  • Remove(*File, RemoveOption) error
  • Browse(*File, BrowseOption) (string, error)

全局配置项(所有配置键)

配置段:[storage]

  • 未检测到配置键(请查看模块源码的 configure 逻辑)

说明

  • setting 一般用于向具体驱动透传专用参数
  • 多实例配置请参考模块源码中的 Config/configure 处理逻辑

Documentation

Index

Constants

View Source
const NAME = "STORAGE"

Variables

This section is empty.

Functions

func Browse

func Browse(code string, opts ...BrowseOption) (string, error)

func Download

func Download(code string, opts ...DownloadOption) (string, error)

func PreviewConfig

func PreviewConfig() string

func Remove

func Remove(code string, opts ...RemoveOption) error

func SaltConfig

func SaltConfig() string

func ThumbnailConfig

func ThumbnailConfig() string

Types

type BrowseOption added in v0.1.0

type BrowseOption struct {
	Headers Map
	Params  Map
	Expires time.Duration
}

type Config

type Config struct {
	Driver  string
	Weight  int
	Prefix  string
	Proxy   bool
	Remote  bool
	Setting Map
}

type Configs

type Configs map[string]Config

type Connection added in v0.8.1

type Connection interface {
	Open() error
	Health() Health
	Close() error

	Upload(string, UploadOption) (*File, error)
	Fetch(*File, FetchOption) (Stream, error)
	Download(*File, DownloadOption) (string, error)
	Remove(*File, RemoveOption) error
	Browse(*File, BrowseOption) (string, error)
}

type DownloadOption added in v0.1.0

type DownloadOption struct {
	Target string
}

type Driver

type Driver interface {
	Connect(*Instance) (Connection, error)
}

type FetchOption added in v0.1.0

type FetchOption struct {
	Start int64
	End   int64
}

type File

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

func Decode

func Decode(code string) (*File, error)

func Upload

func Upload(from Any, opts ...UploadOption) (*File, error)

func UploadTo

func UploadTo(base string, from Any, opts ...UploadOption) (*File, error)

func (*File) Base

func (f *File) Base() string

func (*File) Code

func (f *File) Code() string

func (*File) File

func (f *File) File() string

func (*File) Key added in v0.1.0

func (f *File) Key() string

func (*File) Name

func (f *File) Name() string

func (*File) Prefix added in v0.1.0

func (f *File) Prefix() string

func (*File) Proxy

func (f *File) Proxy() bool

func (*File) Remote

func (f *File) Remote() bool

func (*File) Size

func (f *File) Size() int64

func (*File) Type

func (f *File) Type() string

type Health

type Health struct {
	Workload int64
}

type Instance

type Instance struct {
	Name    string
	Config  Config
	Setting Map
	// contains filtered or unexported fields
}

func (*Instance) NewFile added in v0.8.1

func (i *Instance) NewFile(prefix, key, typee string, size int64) *File

NewFile creates a storage file metadata object for drivers.

type Module

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

func (*Module) Browse

func (m *Module) Browse(code string, opts ...BrowseOption) (string, error)

func (*Module) Close added in v0.8.1

func (m *Module) Close()

func (*Module) Config

func (m *Module) Config(global Map)

func (*Module) Download

func (m *Module) Download(code string, opts ...DownloadOption) (string, error)

func (*Module) Fetch added in v0.1.0

func (m *Module) Fetch(code string, opts ...FetchOption) (Stream, error)

func (*Module) Open added in v0.8.1

func (m *Module) Open()

func (*Module) Register

func (m *Module) Register(name string, value Any)

func (*Module) RegisterConfig added in v0.8.1

func (m *Module) RegisterConfig(name string, cfg Config)

func (*Module) RegisterConfigs added in v0.8.1

func (m *Module) RegisterConfigs(configs Configs)

func (*Module) RegisterDriver added in v0.8.1

func (m *Module) RegisterDriver(name string, driver Driver)

func (*Module) Remove

func (m *Module) Remove(code string, opts ...RemoveOption) error

func (*Module) Setup added in v0.8.1

func (m *Module) Setup()

func (*Module) Start added in v0.8.1

func (m *Module) Start()

func (*Module) Stop added in v0.8.1

func (m *Module) Stop()

func (*Module) Upload

func (m *Module) Upload(original string, opts ...UploadOption) (*File, error)

func (*Module) UploadTo

func (m *Module) UploadTo(base string, original string, opts ...UploadOption) (*File, error)

type RemoveOption added in v0.1.0

type RemoveOption struct{}

type Stream added in v0.1.0

type Stream interface {
	io.Reader
	io.Seeker
	io.Closer
	io.ReaderAt
}

func Fetch added in v0.1.0

func Fetch(code string, opts ...FetchOption) (Stream, error)

type UploadOption added in v0.1.0

type UploadOption struct {
	Key    string
	Prefix string

	Mimetype string
	Metadata Map
	Tags     Map
	Expires  time.Time
}

Jump to

Keyboard shortcuts

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