CloudStore

package module
v0.0.0-...-aad1a02 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: Apache-2.0 Imports: 29 Imported by: 0

README

CloudStore - 云储存集成

国内各大云存储服务接口集成,让云存储使用更方便简单。

目前集成的有:阿里云OSS,百度云BOS腾讯云COS华为云OBS七牛云又拍云Minio

为什么要有这个项目?

为了一劳永逸...

为了变得更懒...

如果上传文件到各大云存储,都变成下面这样:

clientBOS.Upload(tmpFile, saveFile)     // 百度云
clientCOS.Upload(tmpFile, saveFile)     // 腾讯云
clientMinio.Upload(tmpFile, saveFile)   // Minio
clientOBS.Upload(tmpFile, saveFile)     // 华为云
clientOSS.Upload(tmpFile, saveFile)     // 阿里云
clientUpYun.Upload(tmpFile, saveFile)   // 又拍云
clientQiniu.Upload(tmpFile, saveFile)   // 七牛云

如果各大云存储删除文件对象,都变成下面这样:

clientXXX.Delete(file1, file2, file3, ...)

不需要翻看各大云存储服务的一大堆文档,除了创建的客户端对象不一样之外,调用的方法和参数都一毛一样,会不会很爽?

目前初步实现的功能接口

type CloudStore interface {
	Delete(objects ...string) (err error)                                             // 删除文件
	GetSignURL(object string, expire int64) (link string, err error)                  // 文件访问签名
	IsExist(object string) (err error)                                                // 判断文件是否存在
	Lists(prefix string) (files []File, err error)                                    // 文件前缀,列出文件
	Upload(tmpFile string, saveFile string, headers ...map[string]string) (err error) // 上传文件
	Download(object string, savePath string) (err error)                              // 下载文件
	GetInfo(object string) (info File, err error)                                     // 获取指定文件信息
}

目前集成和实现的功能

TODO:

  • 注意,domain 参数要处理一下,最后统一不带"/"
  • 最后获取的签名链接,替换成绑定的域名
  • timeout 时间要处理一下,因为一些非内网方式上传文件,在大文件的时候,5分钟或者10分钟都有可能会超时
  • Lists方法在查询列表的时候,需要对prefix参数做下处理

注意

所有云存储的endpoint,在配置的时候都是不带 http://或者https://

DocHub 可用云存储

  • 百度云 BOS,需要自行压缩svg文件为gzip
  • 腾讯云 COS,需要自行压缩svg文件为gzip
  • 阿里云 OSS,需要自行压缩svg文件为gzip
  • Minio,需要自行压缩svg文件为gzip
  • 七牛云存储,在上传svg的时候不需要压缩,svg访问的时候,云存储自行压缩了
  • 又拍云,在上传svg的时候不需要压缩,svg访问的时候,云存储自行压缩了
  • 华为云 OBS,在上传svg的时候不需要压缩,svg访问的时候,云存储自行压缩了

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressByGzip

func CompressByGzip(tmpFile, saveFile string) (err error)

func MD5Crypt

func MD5Crypt(str string) string

MD5 Crypt

Types

type BOS

type BOS struct {
	AccessKey string
	SecretKey string
	Bucket    string
	Endpoint  string
	Domain    string
	Client    *bos.Client
}

func NewBOS

func NewBOS(accessKey, secretKey, bucket, endpoint, domain string) (b *BOS, err error)

new bos

func (*BOS) Delete

func (b *BOS) Delete(objects ...string) (err error)

func (*BOS) Download

func (b *BOS) Download(object string, savePath string) (err error)

func (*BOS) GetInfo

func (b *BOS) GetInfo(object string) (info File, err error)

func (*BOS) GetSignURL

func (b *BOS) GetSignURL(object string, expire int64) (link string, err error)

func (*BOS) IsExist

func (b *BOS) IsExist(object string) (err error)

func (*BOS) Lists

func (b *BOS) Lists(prefix string) (files []File, err error)

func (*BOS) Upload

func (b *BOS) Upload(tmpFile, saveFile string, headers ...map[string]string) (err error)

type COS

type COS struct {
	AccessKey string
	SecretKey string
	Bucket    string
	AppID     string
	Region    string
	Domain    string
	Client    *cos.Client
}

func NewCOS

func NewCOS(accessKey, secretKey, bucket, appId, region, domain string) (c *COS, err error)

func (*COS) Delete

func (c *COS) Delete(objects ...string) (err error)

func (*COS) Download

func (c *COS) Download(object string, savePath string) (err error)

func (*COS) GetInfo

func (c *COS) GetInfo(object string) (info File, err error)

func (*COS) GetSignURL

func (c *COS) GetSignURL(object string, expire int64) (link string, err error)

func (*COS) IsExist

func (c *COS) IsExist(object string) (err error)

func (*COS) Lists

func (c *COS) Lists(prefix string) (files []File, err error)

func (*COS) Upload

func (c *COS) Upload(tmpFile, saveFile string, headers ...map[string]string) (err error)

type CloudStore

type CloudStore interface {
	Delete(objects ...string) (err error)                                             // 删除文件
	GetSignURL(object string, expire int64) (link string, err error)                  // 文件访问签名
	IsExist(object string) (err error)                                                // 判断文件是否存在
	Lists(prefix string) (files []File, err error)                                    // 文件前缀,列出文件
	Upload(tmpFile string, saveFile string, headers ...map[string]string) (err error) // 上传文件
	Download(object string, savePath string) (err error)                              // 下载文件
	GetInfo(object string) (info File, err error)                                     // 获取指定文件信息
}

type File

type File struct {
	ModTime time.Time
	Name    string
	Size    int64
	IsDir   bool
	Header  map[string]string
}

type MinIO

type MinIO struct {
	AccessKey string
	SecretKey string
	Bucket    string
	Endpoint  string
	Domain    string
	Client    *minio.Client
}

func NewMinIO

func NewMinIO(accessKey, secretKey, bucket, endpoint, domain string) (m *MinIO, err error)

func (*MinIO) Delete

func (m *MinIO) Delete(objects ...string) (err error)

func (*MinIO) Download

func (m *MinIO) Download(object string, savePath string) (err error)

func (*MinIO) GetInfo

func (m *MinIO) GetInfo(object string) (info File, err error)

func (*MinIO) GetSignURL

func (m *MinIO) GetSignURL(object string, expire int64) (link string, err error)

func (*MinIO) IsExist

func (m *MinIO) IsExist(object string) (err error)

func (*MinIO) Lists

func (m *MinIO) Lists(prefix string) (files []File, err error)

func (*MinIO) Upload

func (m *MinIO) Upload(tmpFile, saveFile string, headers ...map[string]string) (err error)

type OBS

type OBS struct {
	AccessKey string
	SecretKey string
	Bucket    string
	Endpoint  string
	Domain    string
	Client    *obs.ObsClient
}

func NewOBS

func NewOBS(accessKey, secretKey, bucket, endpoint, domain string) (o *OBS, err error)

func (*OBS) Delete

func (o *OBS) Delete(objects ...string) (err error)

func (*OBS) Download

func (o *OBS) Download(object string, savePath string) (err error)

func (*OBS) GetInfo

func (o *OBS) GetInfo(object string) (info File, err error)

func (*OBS) GetSignURL

func (o *OBS) GetSignURL(object string, expire int64) (link string, err error)

func (*OBS) IsExist

func (o *OBS) IsExist(object string) (err error)

func (*OBS) Lists

func (o *OBS) Lists(prefix string) (files []File, err error)

func (*OBS) Upload

func (o *OBS) Upload(tmpFile, saveFile string, headers ...map[string]string) (err error)

type OSS

type OSS struct {
	AccessKey string
	SecretKey string
	Endpoint  string
	Bucket    string
	Domain    string
	Client    *oss.Bucket
}

func NewOSS

func NewOSS(accessKey, secretKey, endpoint, bucket, domain string) (o *OSS, err error)

New OSS

func (*OSS) Delete

func (o *OSS) Delete(objects ...string) (err error)

func (*OSS) Download

func (o *OSS) Download(object string, savePath string) (err error)

func (*OSS) GetInfo

func (o *OSS) GetInfo(object string) (info File, err error)

func (*OSS) GetSignURL

func (o *OSS) GetSignURL(object string, expire int64) (link string, err error)

func (*OSS) IsExist

func (o *OSS) IsExist(object string) (err error)

func (*OSS) Lists

func (o *OSS) Lists(prefix string) (files []File, err error)

func (*OSS) Upload

func (o *OSS) Upload(tmpFile, saveFile string, headers ...map[string]string) (err error)

type QINIU

type QINIU struct {
	AccessKey string
	SecretKey string
	Bucket    string
	Domain    string
	Zone      *storage.Zone

	BucketManager *storage.BucketManager
	// contains filtered or unexported fields
}

func NewQINIU

func NewQINIU(accessKey, secretKey, bucket, domain string) (q *QINIU, err error)

func (*QINIU) Delete

func (q *QINIU) Delete(objects ...string) (err error)

func (*QINIU) Download

func (q *QINIU) Download(object string, savePath string) (err error)

func (*QINIU) GetInfo

func (q *QINIU) GetInfo(object string) (info File, err error)

func (*QINIU) GetSignURL

func (q *QINIU) GetSignURL(object string, expire int64) (link string, err error)

func (*QINIU) IsExist

func (q *QINIU) IsExist(object string) (err error)

func (*QINIU) Lists

func (q *QINIU) Lists(prefix string) (files []File, err error)

func (*QINIU) Upload

func (q *QINIU) Upload(tmpFile, saveFile string, headers ...map[string]string) (err error)

TODO: 目前没发现有可以设置header的地方

type UpYun

type UpYun struct {
	Bucket   string
	Operator string
	Password string
	Domain   string
	Client   *upyun.UpYun
	// contains filtered or unexported fields
}

func NewUpYun

func NewUpYun(bucket, operator, password, domain, secret string) *UpYun

func (*UpYun) Delete

func (u *UpYun) Delete(objects ...string) (err error)

func (*UpYun) Download

func (u *UpYun) Download(object string, savePath string) (err error)

func (*UpYun) GetInfo

func (u *UpYun) GetInfo(object string) (info File, err error)

func (*UpYun) GetSignURL

func (u *UpYun) GetSignURL(object string, expire int64) (link string, err error)

https://help.upyun.com/knowledge-base/cdn-token-limite/

func (*UpYun) IsExist

func (u *UpYun) IsExist(object string) (err error)

func (*UpYun) Lists

func (u *UpYun) Lists(prefix string) (files []File, err error)

func (*UpYun) Upload

func (u *UpYun) Upload(tmpFile, saveFile string, headers ...map[string]string) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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