clouds

package module
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: MIT Imports: 3 Imported by: 0

README

clouds

介绍

CloudStorage分布式云存储系统简称CloudS。 CloudS系统面向客户端应用提供非结构化数据存储服务,可以上传保存图片、音视频、程序,静态资源文件如css/js等非结构化数据。 CloudS系统将应用上传数据存储于多个硬盘中并实现冗余计算避免单个磁盘损坏而导致数据丢失。

依赖

使用 coauth 实现令牌的管理, 开始使用 clouds 前建议先了解其初始化设置。

安装

go get -u gitee.com/shishshinedone/clouds

使用

1.初始化
默认初始化
auth := coauth.NewCoauth(
    "http://0.0.0.0:0000", 
    "username", 
    "password",
)
s := clouds.NewClouds(
    "http://0.0.0.0:0001", 
    "storage-name", 
    auth, 
)
err := s.Init()
if err != nil {
    panic(err)
}
  • storage-name 为存储空间名称, 不同模块应当相互独立
  • s.Init()会检查存储空间是否存在, 不存在将会自动创建
带参数初始化
auth := coauth.NewCoauth(
    "http://0.0.0.0:0000", 
    "username", 
    "password",
)
s := clouds.NewClouds(
    "http://0.0.0.0:0001", 
    "storage-name", 
    auth, 
    clouds.WithVersion(clouds.VersionOriginal),
    clouds.WithRegion("fujian"),
    clouds.WithTimeout(time.Second*15),
)
err := s.Init()
if err != nil {
    panic(err)
}
  • clouds.WithVersion 指定版本号, 当前仅有一个版本且为默认值
  • clouds.WithRegion 指定存储空间存储区域, 默认为fj-qz
  • clouds.WithTimeout 指定连接超时时间, 默认不超时
2.添加文件
var reader io.Reader = strings.NewReader("strstrstrstrstrstrstrstr")
stat, err := s.Add("test.txt", reader)
if err != nil {
    panic(err)
}
fmt.Println(stat.Name(), stat.Size())
3.获取文件流
reader, err = s.Get("test.txt")
if err != nil {
    panic(err)
}
data, err := io.ReadAll(reader)
if err != nil {
    panic(err)
}
fmt.Println(string(data))
4.获取文件状态
stat, err := s.Stat("test.txt")
if err != nil {
    panic(err)
}
fmt.Println(stat.Name(), stat.Size(), stat.ModTime().Local())
5.删除文件
err = s.Del("test.txt")
if err != nil {
    panic(err)
}
6.根据文件名前缀查找文件
objects, err := s.Find("test")
if err != nil {
    panic(err)
}
fmt.Println(objects)
  • 仅列出当前存储空间的文件, 受限于服务器实现当前版本仅返回文件名列表
7.列出所有文件
objects, err = s.List()
if err != nil {
    panic(err)
}
fmt.Println(objects)
  • 仅列出当前存储空间的文件, 受限于服务器实现当前版本仅返回文件名列表
8.销毁存储空间
err = s.Destroy()
if err != nil {
    panic(err)
}
  • 删除所有文件后成功后, 存储空间才会被删除

错误

1.clouds.ErrExisted

存储对象重名或已存在,常出现在s.Add等操作中

2.clouds.ErrNotExisted

该存储对象不存在,常出现在s.Get、s.Stat、s.Del等操作中

TODO

1.列出所有存储空间
  • 没有使用场景, 暂不实现
2.拷贝文件
  • 没有使用场景, 暂不实现
3.根据文件名前缀删除文件
  • 没有使用场景, 暂不实现
4.添加或更新文件标签
  • 没有使用场景, 暂不实现
5.查询文件标签
  • 没有使用场景, 暂不实现
6.删除文件标签
  • 没有使用场景, 暂不实现

Documentation

Index

Constants

View Source
const (
	VersionOriginal version = clouds_core.VersionOriginal
)

Variables

View Source
var (
	ErrExisted    = clouds_core.ErrExisted
	ErrNotExisted = clouds_core.ErrNotExisted
)

Functions

This section is empty.

Types

type Clouds

type Clouds clouds_core.Clouds

func NewClouds

func NewClouds(addr, name string, auth coauth.Coauth, optionArray ...Option) Clouds

type CloudsAdd added in v1.0.7

type CloudsAdd clouds_core.CloudsAdd

type CloudsStat added in v1.0.4

type CloudsStat clouds_core.CloudsStat

type Option

type Option func(o *clouds_core.Options)

func WithRegion

func WithRegion(value string) Option

func WithTimeout

func WithTimeout(value time.Duration) Option

func WithVersion

func WithVersion(value version) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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