Documentation
¶
Overview ¶
Package core defines shared storage contracts, metadata, config, and small helpers.
Index ¶
- Constants
- Variables
- func JoinObjectURL(baseURL, objectPath string) string
- func NormalizeSourceTTL(ttl time.Duration) time.Duration
- func SignSourceURL(baseURL, objectPath, secret string, ttl time.Duration, now time.Time) (string, error)
- func SourceSignature(objectPath string, expires int64, secret string) string
- func VerifySourceSignature(objectPath, expires, signature, secret string, now time.Time) error
- type Config
- type DriverConfig
- type FileHeader
- type FileInfo
- type FileStream
- type Handler
- type Namer
- type Object
- type StoragePolicy
- type UploadCredential
Constants ¶
View Source
const ( UploadModeLocalChunk = "local_chunk" UploadModeDirectPut = "direct_put" UploadModeMultipartPut = "multipart_put" )
View Source
const ( DefaultSourceTTL = 7 * 24 * time.Hour DefaultSourcePath = "/storage/source" )
Variables ¶
View Source
var ( ErrFileTooBig = errors.New("文件过大") ErrFileExists = errors.New("文件已存在") ErrFileNotFound = errors.New("文件不存在") ErrNameInvalid = errors.New("文件名不合法") ErrUnknownDriver = errors.New("未知存储驱动") )
View Source
var ( ErrSourceExpired = errors.New("storage source url expired") ErrSourceSignatureInvalid = errors.New("storage source signature invalid") ErrSourceSecretRequired = errors.New("storage source secret required") )
View Source
var DefaultNamer = &Namer{
DirRule: "{date}",
FileRule: "{uuid}{ext}",
}
Functions ¶
func JoinObjectURL ¶ added in v0.1.3
func SignSourceURL ¶
Types ¶
type Config ¶
type Config struct {
StoreName string `mapstructure:"-" json:"-" yaml:"-"`
DefaultStore bool `mapstructure:"-" json:"-" yaml:"-"`
Driver string `mapstructure:"driver"`
TempDir string `mapstructure:"temp_dir"`
MaxSize int64 `mapstructure:"max_size"`
ChunkSize int64 `mapstructure:"chunk_size"`
TokenTTL time.Duration `mapstructure:"token_ttl"`
DirRule string `mapstructure:"dir_rule"`
FileRule string `mapstructure:"file_rule"`
AllowedExtensions []string `mapstructure:"allowed_extensions"`
Policy StoragePolicy `mapstructure:"policy"`
DriverConfig DriverConfig `mapstructure:",remain"`
}
func (Config) DriverBool ¶
func (Config) DriverString ¶
type DriverConfig ¶
type FileInfo ¶
type FileInfo struct {
Name string
Path string
Size int64
MIMEType string
ModTime time.Time
Progress func(uploaded, total int64)
Metadata map[string]string
}
FileInfo 文件元信息
type FileStream ¶
type FileStream struct {
// contains filtered or unexported fields
}
FileStream 文件流
func NewFileStream ¶
func NewFileStream(reader io.Reader, info FileInfo) *FileStream
func (*FileStream) Close ¶
func (f *FileStream) Close() error
func (*FileStream) Info ¶
func (f *FileStream) Info() FileInfo
type Handler ¶
type Handler interface {
// Put 服务端上传文件
Put(file FileHeader) error
// Get 获取文件内容
Get(path string) (io.ReadCloser, error)
// Delete 删除文件
Delete(paths ...string) error
// List 列出目录
List(path string) ([]Object, error)
// Source 获取文件访问 URL
Source(path string, ttl time.Duration) (string, error)
// Token 生成客户端直传凭证(S3 返回 presigned URL,local 返回路径)
Token(fileInfo FileInfo, ttl time.Duration) (*UploadCredential, error)
}
Handler 文件系统存储驱动接口
type Namer ¶
Namer 文件名生成器,支持模板变量 {uuid} / {randomkey16} / {randomkey8} / {timestamp} / {datetime} {date} / {year} / {month} / {day} / {hour} / {minute} / {second} {originname} / {ext}
type StoragePolicy ¶
type StoragePolicy struct {
Driver string `mapstructure:"driver" json:"driver"`
Name string `mapstructure:"name" json:"name"`
Bucket string `mapstructure:"bucket" json:"bucket"`
Endpoint string `mapstructure:"endpoint" json:"endpoint"`
EndpointInner string `mapstructure:"endpoint_inner" json:"endpoint_inner"`
CDNURL string `mapstructure:"cdn_url" json:"cdn_url"`
Region string `mapstructure:"region" json:"region"`
AccessKey string `mapstructure:"access_key" json:"access_key"`
SecretKey string `mapstructure:"secret_key" json:"secret_key"`
LocalDir string `mapstructure:"local_dir" json:"local_dir"`
}
StoragePolicy is a unified storage strategy shape for config files or DB rows. Driver decides how these common fields are mapped to a concrete SDK config.
func (StoragePolicy) Empty ¶
func (p StoragePolicy) Empty() bool
type UploadCredential ¶
type UploadCredential struct {
Mode string `json:"mode"` // 上传模式:local_chunk / direct_put / multipart_put
UploadID string `json:"upload_id"` // 上传会话 ID
Gateway string `json:"gateway"` // 存储类型
ChunkSize int64 `json:"chunk_size"` // 分片大小,0 为不分片
ChunkNum int `json:"chunk_num"` // 总分片数
UploadURLs []string `json:"upload_urls"` // 每片的直传 URL
CompleteURL string `json:"complete_url"` // 完成合并的 URL
Path string `json:"path"` // 存储路径
AccessPath string `json:"access_path"` // 前端访问值
}
UploadCredential 客户端直传凭证
Click to show internal directories.
Click to hide internal directories.