Help us shape the future of Go! Take the 2026 Go Developer Survey

storage

package
v0.32.41 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MigrateStorageReq added in v0.32.33

type MigrateStorageReq struct {
	// TargetType 目标后端类型(local / s3 / webdav / …)。
	TargetType string
	// TargetPath 目标本地目录(仅 TargetType=local 时有意义;缺省 = 沿用现配置的 storage_path)。
	TargetPath string
	// DryRun 只算计划不搬(先看再动)。
	DryRun bool
}

MigrateStorageReq 迁移请求(域内形态;契约层同名结构见 contracts 的 idl/storage.thrift)。

type MigrateStorageResult added in v0.32.33

type MigrateStorageResult struct {
	// Switched 是否已切换到目标后端。
	Switched bool
	// Copied 本次复制成功的对象数。
	Copied int64
	// Skipped 目标已存在而跳过的对象数(续跑)。
	Skipped int64
	// Failed 复制失败的对象数(>0 ⇒ 未切换)。
	Failed int64
	// Bytes 复制字节数。
	Bytes int64
	// Objects 计划涉及的对象总数。
	Objects int64
	// FromType 源后端类型。
	FromType string
	// ToType 目标后端类型。
	ToType string
	// Message 人类可读结论(失败摘要 / dry-run 计划)。
	Message string
}

MigrateStorageResult 迁移结果。

type NFSConfig

type NFSConfig struct {
	Server     string `json:"server"`
	Path       string `json:"path"`
	MountPoint string `json:"mount_point"`
	Version    string `json:"version"`
	Options    string `json:"options"`
	Timeout    int32  `json:"timeout"`
	AutoMount  int32  `json:"auto_mount"`
	RetryCount int32  `json:"retry_count"`
	SubPath    string `json:"sub_path"`
}

type ObjectLister added in v0.32.33

type ObjectLister interface {
	// ListReferencedObjectPaths 返回全部被引用的对象路径(去重)。
	// 必须含**软删**记录:软删分享可恢复 ⇒ 它的对象也得搬过去。
	ListReferencedObjectPaths(ctx context.Context) ([]string, error)
}

ObjectLister 列出被 DB 引用的对象路径(admin 域实现)。

路径是**存储相对路径**(与 file_codes.file_path / file_code_files.file_path 同形)。

type ObjectReader added in v0.32.33

type ObjectReader interface {
	// GetFileReader 打开对象读取器;同时给出对象大小(远端驱动写流需确切 size)。
	GetFileReader(ctx context.Context, filePath string) (io.ReadCloser, int64, error)
	// FileExists 对象是否已存在(续跑跳过判定)。
	FileExists(ctx context.Context, filePath string) bool
}

ObjectReader 读对象(当前生效后端)。

由 core/storage 的单例实现(它同时是 Runtime);用类型断言而非接口继承, 免得为迁移去改 Runtime 的既有契约(别的实现者不必跟着改)。

type Runtime

type Runtime interface {
	Reload(cfg *corestorage.StorageConfig) error
	EffectiveType() corestorage.StorageType
}

Runtime 存储运行时接口(bootstrap 注入单例 *storage.StorageService)。

type RuntimePersister

type RuntimePersister interface {
	LoadRuntimeStorage(ctx context.Context) *conf.StorageConfig
	SaveRuntimeStorage(ctx context.Context, cfg *conf.StorageConfig) error
}

RuntimePersister 运行时存储配置持久化(admin 域实现,bootstrap 装配; 存储域不直接碰 system_configs,保持域间零耦合)。

type S3Config

type S3Config struct {
	AccessKeyID     string `json:"access_key_id"`
	SecretAccessKey string `json:"secret_access_key"`
	BucketName      string `json:"bucket_name"`
	EndpointURL     string `json:"endpoint_url"`
	RegionName      string `json:"region_name"`
	Hostname        string `json:"hostname"`
	Proxy           string `json:"proxy"`
}

type Service

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

Service 存储服务

func NewService

func NewService() *Service

NewService 创建存储服务

func (*Service) GetStorageInfo

func (s *Service) GetStorageInfo(ctx context.Context) (*StorageInfo, error)

GetStorageInfo 获取存储信息

func (*Service) MigrateStorage added in v0.32.33

func (s *Service) MigrateStorage(ctx context.Context, req *MigrateStorageReq) (*MigrateStorageResult, error)

MigrateStorage 把存量对象从当前后端搬到目标后端。

流程:校验目标 → 探测目标连通性 → 列举待迁对象 →(dry-run 则到此为止)→ 逐个复制(目标已存在则跳过)→ 全部成功才切换后端。

失败语义:**不切换**(源后端继续在用),并返回失败摘要。

func (*Service) SetObjectLister added in v0.32.33

func (s *Service) SetObjectLister(l ObjectLister)

SetObjectLister 注入对象清单来源(admin 域实现;bootstrap 装配)。

func (*Service) SetPersister

func (s *Service) SetPersister(p RuntimePersister)

SetPersister 注入持久化(在线切换写穿 DB,重启不丢)

func (*Service) SetRuntime

func (s *Service) SetRuntime(rt Runtime)

SetRuntime 注入存储运行时(在线切换后端热生效)

func (*Service) SwitchStorage

func (s *Service) SwitchStorage(ctx context.Context, storageType string) error

SwitchStorage 切换存储类型:校验 → 认证级 Probe → 热重载(新写入立即走新后端) → 更新全局配置 → 持久化到 system_configs(重启不丢)。

func (*Service) TestStorageConnection

func (s *Service) TestStorageConnection(ctx context.Context, storageType string) error

TestStorageConnection 测试存储连接。 local:路径存在可写;s3/webdav:端点 URL 校验(scheme 白名单 + 私网策略) 后做真实 HTTP 探测(不要求认证通过,能建立连接即可)。

func (*Service) UpdateStorageConfig

func (s *Service) UpdateStorageConfig(ctx context.Context, req *UpdateConfigRequest) error

UpdateStorageConfig 更新存储配置。 流程与 SwitchStorage 一致:SSRF 校验 → 认证级 Probe → 热重载 → 更新内存 → 持久化到 system_configs(管理端配置记录,重启后由 bootstrap 恢复)。 注:use_ssl/path_style 未随请求传入时保留现值(use_ssl 缺省 true,与管理端历史行为一致)。

type StorageConfig

type StorageConfig struct {
	Type        string        `json:"type"`
	StoragePath string        `json:"storage_path"`
	WebDAV      *WebDAVConfig `json:"webdav,omitempty"`
	S3          *S3Config     `json:"s3,omitempty"`
	NFS         *NFSConfig    `json:"nfs,omitempty"`
}

type StorageDetail

type StorageDetail struct {
	Type         string `json:"type"`
	Available    bool   `json:"available"`
	StoragePath  string `json:"storage_path"`
	UsagePercent int32  `json:"usage_percent"`
	Error        string `json:"error,omitempty"`
}

type StorageInfo

type StorageInfo struct {
	Current        string                    `json:"current"`
	Effective      string                    `json:"effective"` // 实际生效后端(降级时与 current 不同)
	Available      []string                  `json:"available"`
	StorageDetails map[string]*StorageDetail `json:"storage_details"`
	StorageConfig  *StorageConfig            `json:"storage_config"`
}

type UpdateConfigRequest

type UpdateConfigRequest struct {
	Type string `json:"type"`
	// 扁平形态:内嵌 conf.StorageConfig,JSON 字段同名绑定
	conf.StorageConfig
}

UpdateConfigRequest 更新配置请求 UpdateConfigRequest 存储配置更新请求。

形态:**只有**扁平一种——请求体即 conf.StorageConfig 同构 JSON (type/storage_path/quota/s3/webdav/ftp/sftp/azureblob/hdfs/onedrive/oss..obs), 后端整体校验 → Probe → 热切换 → 持久化。

旧的嵌套形态 {type, config:{storage_path/webdav/s3}} 已删(2026-10-25 删除旧版本 兼容):它只能切 local/webdav/s3 三种、且字段名与实际配置模型对不上(旧契约遗留), 保留它等于让**两种写入口径**并存。

type WebDAVConfig

type WebDAVConfig struct {
	Hostname string `json:"hostname"`
	Username string `json:"username"`
	Password string `json:"password"`
	RootPath string `json:"root_path"`
	URL      string `json:"url"`
}

Jump to

Keyboard shortcuts

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