Documentation
¶
Index ¶
- Variables
- func LoadStorages(ctx context.Context)
- func WithContext(ctx context.Context, storage Storage) context.Context
- type Storage
- func FromContext(ctx context.Context) Storage
- func GetStorageByName(ctx context.Context, name string) (Storage, error)
- func GetStorageByUserIDAndName(ctx context.Context, chatID int64, name string) (Storage, error)
- func GetTelegramStorageByUserID(ctx context.Context, chatID int64) (Storage, error)
- func GetUserStorages(ctx context.Context, chatID int64) []Storage
- func NewStorage(ctx context.Context, cfg storcfg.StorageConfig) (Storage, error)
- type StorageCannotStream
- type StorageConstructor
- type StorageListable
- type StorageReadable
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrStorageNameEmpty = errors.New("storage name is empty")
)
View Source
var Storages = make(map[string]Storage)
View Source
var UserStorages = make(map[int64][]Storage)
Functions ¶
func LoadStorages ¶ added in v0.11.0
Types ¶
type Storage ¶
type Storage interface {
// Init 只应该在创建存储时调用一次
Init(ctx context.Context, cfg storcfg.StorageConfig) error
Type() storenum.StorageType
Name() string
Save(ctx context.Context, reader io.Reader, storagePath string) error
Exists(ctx context.Context, storagePath string) bool
}
func FromContext ¶ added in v0.23.0
func GetStorageByName ¶ added in v0.11.0
GetStorageByName returns storage by name from cache or creates new one It should NOT be used to get storage for user, use GetStorageByUserIDAndName instead
func GetStorageByUserIDAndName ¶ added in v0.11.0
检查 user 是否可用指定的 storage, 若不可用则返回未找到错误
func GetTelegramStorageByUserID ¶ added in v0.52.0
GetTelegramStorageByUserID returns the first enabled Telegram storage for the user
func GetUserStorages ¶ added in v0.11.0
func NewStorage ¶ added in v0.11.0
NewStorage creates a new storage instance based on the provided config and initializes it
type StorageCannotStream ¶ added in v0.23.0
type StorageConstructor ¶ added in v0.11.0
type StorageConstructor func() Storage
type StorageListable ¶ added in v0.52.0
type StorageListable interface {
Storage
ListFiles(ctx context.Context, dirPath string) ([]storagetypes.FileInfo, error)
}
StorageListable 表示支持列举目录内容的存储
type StorageReadable ¶ added in v0.52.0
type StorageReadable interface {
Storage
OpenFile(ctx context.Context, filePath string) (io.ReadCloser, int64, error)
}
StorageReadable 表示支持读取文件内容的存储
Click to show internal directories.
Click to hide internal directories.