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

storage

package
v0.18.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 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) 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"`
	Config struct {
		StoragePath string        `json:"storage_path"`
		WebDAV      *WebDAVConfig `json:"webdav"`
		S3          *S3Config     `json:"s3"`
		NFS         *NFSConfig    `json:"nfs"`
	} `json:"config"`

	// 扁平形态(新):内嵌 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}} 仍兼容(走既有局部更新逻辑)。

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