upyun

package
v0.2.25 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileSize

func FileSize(f *os.File) int64

func StringMd5

func StringMd5(s string) string

Types

type DirInfo

type DirInfo struct {
	Name string
	Type string
	Size int64
	Time int64
}

type UpYun

type UpYun struct {
	TimeOut int
	Debug   bool
	// contains filtered or unexported fields
}

func NewUpYun

func NewUpYun(bucketName, userName, passWord string) *UpYun

*

  • 初始化 UpYun 存储接口
  • @param bucketName 空间名称
  • @param userName 操作员名称
  • @param passWord 密码
  • return UpYun object

func (*UpYun) DeleteFile

func (u *UpYun) DeleteFile(file string) error

*

  • 删除文件
  • @param file 文件路径(包含文件名)
  • return error

func (*UpYun) GetBucketUsage

func (u *UpYun) GetBucketUsage() (float64, error)

*

  • 获取总体空间的占用信息
  • return 空间占用量,失败返回0.0

func (*UpYun) GetFileInfo

func (u *UpYun) GetFileInfo(file string) map[string]string

*

  • 获取文件信息
  • @param file 文件路径(包含文件名)
  • return array('type': file | folder, 'size': file size, 'date': unix time) 或 nil

func (*UpYun) GetFolderUsage

func (u *UpYun) GetFolderUsage(path string) (float64, error)

*

  • 获取某个子目录的占用信息
  • @param $path 目标路径
  • return 空间占用量和error,失败空间占用量返回0.0

func (*UpYun) GetWritedFileInfo

func (u *UpYun) GetWritedFileInfo(key string) string

*

  • 获取上传文件后的信息(仅图片空间有返回数据)
  • @param key 信息字段名(x-upyun-width、x-upyun-height、x-upyun-frames、x-upyun-file-type)
  • return string or ""

func (*UpYun) MkDir

func (u *UpYun) MkDir(path string, autoMkdir bool) error

*

  • 创建目录
  • @param path 目录路径
  • @param auto_mkdir=false 是否自动创建父级目录
  • return error

func (*UpYun) ReadDir

func (u *UpYun) ReadDir(path string) ([]*DirInfo, error)

*

  • 读取目录列表
  • @param path 目录路径
  • return DirInfo数组 或 nil

func (*UpYun) ReadFile

func (u *UpYun) ReadFile(file string, outFile *os.File) error

*

  • 读取文件
  • @param file 文件路径(包含文件名)
  • @param outFile 可传递文件IO数据流(结果返回true or false)
  • return error

func (*UpYun) RmDir

func (u *UpYun) RmDir(dir string) error

*

  • 删除目录
  • @param path 目录路径
  • return error

func (*UpYun) SetApiDomain

func (u *UpYun) SetApiDomain(domain string)

* * 切换 API 接口的域名 * @param domain { 默认 v0.api.upyun.com 自动识别,

    v1.api.upyun.com 电信,
    v2.api.upyun.com 联通,
    v3.api.upyun.com 移动
}

* return 无

func (*UpYun) SetContentMD5

func (u *UpYun) SetContentMD5(str string)

*

  • 设置待上传文件的 Content-MD5 值(如又拍云服务端收到的文件MD5值与用户设置的不一致,
  • 将回报 406 Not Acceptable 错误)
  • @param str (文件 MD5 校验码)
  • return 无

func (*UpYun) SetFileSecret

func (u *UpYun) SetFileSecret(str string)

*

  • 设置待上传文件的 访问密钥(注意:仅支持图片空!,设置密钥后,无法根据原文件URL直接访问,需带 URL 后面加上 (缩略图间隔标志符+密钥) 进行访问)
  • 如缩略图间隔标志符为 ! ,密钥为 bac,上传文件路径为 /folder/test.jpg ,那么该图片的对外访问地址为: http://空间域名/folder/test.jpg!bac
  • @param $str (文件 MD5 校验码)
  • return null;

func (*UpYun) SetTimeout

func (u *UpYun) SetTimeout(time int)

*

  • 设置连接超时时间
  • @param time 秒
  • return 无

func (*UpYun) Version

func (u *UpYun) Version() string

func (*UpYun) WriteFile

func (u *UpYun) WriteFile(filePath string, inFile *os.File, autoMkdir bool) error

*

  • 上传文件
  • @param filePath 文件路径(包含文件名)
  • @param inFile 文件IO数据流
  • @param autoMkdir 是否自动创建父级目录(最深10级目录)
  • return error

type UpyunConfig

type UpyunConfig struct {
	Host       string `toml:"host" mapstructure:"host"  validate:"nonzero"`
	BucketName string `toml:"bucket_name" mapstructure:"bucket_name" validate:"nonzero"`
	UserName   string `toml:"user_name" mapstructure:"user_name" validate:"nonzero"`
	PassWord   string `toml:"pass_word" mapstructure:"pass_word" validate:"nonzero"`
}

type UpyunUploader

type UpyunUploader struct {
	Config UpyunConfig
}

func (*UpyunUploader) PutFile

func (u *UpyunUploader) PutFile(localPath, targetPath string) (err error)

func (UpyunUploader) Upload

func (u UpyunUploader) Upload(t *model.Task) error

Jump to

Keyboard shortcuts

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