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访问的时候,云存储自行压缩了
Expand ▾ Collapse ▴

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfigType

func GetConfigType(config Config) (cfg interface{})

Types

type CloudStore

type CloudStore struct {
	Private       bool
	StoreType     StoreType
	CanGZIP       bool
	Client        interface{}
	Config        interface{}
	Expire        int64
	PublicDomain  string
	PrivateDomain string
}

func NewCloudStore

func NewCloudStore(storeConf Config, private bool) (cs *CloudStore, err error)

    创建云存储 config 相应存储的struct指针 storetype 云存储对应的名字 private false不使用普通网络

    func NewCloudStoreWithConfig

    func NewCloudStoreWithConfig(storeConfig interface{}, storeType StoreType, private bool) (cs *CloudStore, err error)

    func (*CloudStore) Delete

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

    func (*CloudStore) GetPublicDomain

    func (c *CloudStore) GetPublicDomain() (domain string)

    func (*CloudStore) GetSignURL

    func (c *CloudStore) GetSignURL(object string) (link string)

    func (*CloudStore) IsExist

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

      err 返回 nil,表示文件存在,否则表示文件不存在

      func (*CloudStore) Lists

      func (c *CloudStore) Lists(object string) (files []cloud.File, err error)

      func (*CloudStore) PingTest

      func (c *CloudStore) PingTest() (err error)

      func (*CloudStore) Upload

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

      type Config

      type Config struct {
      	AccessKey           string
      	SecretKey           string
      	Endpoint            string
      	Region              string
      	AppId               string
      	PublicBucket        string
      	PublicBucketDomain  string
      	PrivateBucket       string
      	PrivateBucketDomain string
      	Expire              int64
      	CloudType           StoreType
      }

      type ConfigBos

      type ConfigBos struct {
      	AccessKey           string `store:"access-key" fieldName:"AccessKey"`
      	SecretKey           string `store:"secret-key" fieldName:"SecretKey"`
      	Endpoint            string `store:"endpoint" fieldName:"Endpoint"`
      	PublicBucket        string `store:"public-bucket" fieldName:"PublicBucket"`
      	PublicBucketDomain  string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`
      	PrivateBucket       string `store:"private-bucket" fieldName:"PrivateBucket"`
      	PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`
      	Expire              int64  `store:"expire" fieldName:"Expire"`
      }

      type ConfigCos

      type ConfigCos struct {
      	AccessKey           string `store:"access-key" fieldName:"AccessKey"`
      	SecretKey           string `store:"secret-key" fieldName:"SecretKey"`
      	Region              string `store:"region" fieldName:"Region"`
      	AppId               string `store:"app-id" fieldName:"AppId"`
      	PublicBucket        string `store:"public-bucket" fieldName:"PublicBucket"`
      	PublicBucketDomain  string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`
      	PrivateBucket       string `store:"private-bucket" fieldName:"PrivateBucket"`
      	PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`
      	Expire              int64  `store:"expire" fieldName:"Expire"`
      }

      type ConfigMinio

      type ConfigMinio struct {
      	AccessKey           string `store:"access-key" fieldName:"AccessKey"`
      	SecretKey           string `store:"secret-key" fieldName:"SecretKey"`
      	Endpoint            string `store:"endpoint" fieldName:"Endpoint"`
      	PublicBucket        string `store:"public-bucket" fieldName:"PublicBucket"`
      	PublicBucketDomain  string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`
      	PrivateBucket       string `store:"private-bucket" fieldName:"PrivateBucket"`
      	PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`
      	Expire              int64  `store:"expire" fieldName:"Expire"`
      }

      type ConfigObs

      type ConfigObs struct {
      	AccessKey           string `store:"access-key" fieldName:"AccessKey"`
      	SecretKey           string `store:"secret-key" fieldName:"SecretKey"`
      	Endpoint            string `store:"endpoint" fieldName:"Endpoint"`
      	PublicBucket        string `store:"public-bucket" fieldName:"PublicBucket"`
      	PublicBucketDomain  string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`
      	PrivateBucket       string `store:"private-bucket" fieldName:"PrivateBucket"`
      	PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`
      	Expire              int64  `store:"expire" fieldName:"Expire"`
      }

      type ConfigOss

      type ConfigOss struct {
      	AccessKey           string `store:"access-key" fieldName:"AccessKey"`
      	SecretKey           string `store:"secret-key" fieldName:"SecretKey"`
      	Endpoint            string `store:"endpoint" fieldName:"Endpoint"`
      	PublicBucket        string `store:"public-bucket" fieldName:"PublicBucket"`
      	PublicBucketDomain  string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`
      	PrivateBucket       string `store:"private-bucket" fieldName:"PrivateBucket"`
      	PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`
      	Expire              int64  `store:"expire" fieldName:"Expire"`
      }

      type ConfigQiniu

      type ConfigQiniu struct {
      	AccessKey           string `store:"access-key" fieldName:"AccessKey"`
      	SecretKey           string `store:"secret-key" fieldName:"SecretKey"`
      	Endpoint            string `store:"endpoint" fieldName:"Endpoint"`
      	PublicBucket        string `store:"public-bucket" fieldName:"PublicBucket"`
      	PublicBucketDomain  string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`
      	PrivateBucket       string `store:"private-bucket" fieldName:"PrivateBucket"`
      	PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`
      	Expire              int64  `store:"expire" fieldName:"Expire"`
      }

      type ConfigUpYun

      type ConfigUpYun struct {
      	AccessKey           string `store:"access-key" fieldName:"AccessKey"`
      	SecretKey           string `store:"secret-key" fieldName:"SecretKey"`
      	Endpoint            string `store:"endpoint" fieldName:"Endpoint"`
      	PublicBucket        string `store:"public-bucket" fieldName:"PublicBucket"`
      	PublicBucketDomain  string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`
      	PrivateBucket       string `store:"private-bucket" fieldName:"PrivateBucket"`
      	PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`
      	Expire              int64  `store:"expire" fieldName:"Expire"`
      }

      type StoreType

      type StoreType string
      var (
      	Oss   StoreType = "oss"   //oss存储
      	Minio StoreType = "minio" //minio存储
      	Cos   StoreType = "cos"   //腾讯云存储
      	Obs   StoreType = "obs"   //华为云存储
      	Bos   StoreType = "bos"   //百度云存储
      	Qiniu StoreType = "qiniu" //七牛云储存
      	Upyun StoreType = "upyun" //又拍云存储
      )

      Directories

      Path Synopsis