transfer

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: Apache-2.0 Imports: 16 Imported by: 7

README

transfer

提供各种传输,包括上传和下载

功能

  • 阿里云OSS
  • 腾讯云COS
  • FTP
  • 本地文件模板
  • Http
  • Webdav
  • SCP
  • SSH

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorNotSupportStorage 不支持的存储类型
	ErrorNotSupportStorage = &gox.CodeError{ErrorCode: 100, Message: "不支持的存储类型"}
	// ErrorDownload 文件下载失败
	ErrorDownload = &gox.CodeError{ErrorCode: 101, Message: "文件下载失败"}
	// ErrorUpload 文件上传失败
	ErrorUpload = &gox.CodeError{ErrorCode: 102, Message: "文件上传失败"}
)

Functions

func NewResty added in v1.0.3

func NewResty() *resty.Request

NewResty Resty客户端

func RestyStringBody added in v1.0.3

func RestyStringBody(rsp *resty.Response) string

RestyStringBody 字符串形式的结果

Types

type Cos

type Cos struct {
	// 通信地址
	Url string
	// 基础路径
	Base string
	// 授权,相当于用户名
	SecretId string
	// 授权,相当于密码
	SecretKey string
	//  临时密钥
	Token string
	// 分隔符
	Separator string `default:"/"`
}

Cos 腾讯云对象存储

func (*Cos) Download added in v1.0.7

func (c *Cos) Download(srcFilename string, destFilename string) (err error)

func (Cos) Upload added in v1.0.7

func (c Cos) Upload(destFilename string, srcFilename string) (err error)

type Downloader added in v1.0.3

type Downloader interface {
	// Download 下载文件
	Download(srcFilename string, destFilename string) (err error)
}

Downloader 下载

type File added in v0.0.3

type File struct {
	// Type 类型
	Type FileType `json:"type" validate:"required,oneof=http oss cos ftp local"`
	// Filename 文件名
	Filename string `json:"filename" validate:"required"`
	// Checksum 文件校验
	Checksum gox.Checksum `json:"checksum" validate:"omitempty,structonly"`
	// Storage 存储
	Storage interface{} `json:"storage"`
}

File 文件

func NewCosFile added in v1.0.7

func NewCosFile(filename string, cos Cos) File

NewCosFile 创建一个腾讯云对象存储文件

func NewFile added in v1.0.3

func NewFile(fileType FileType, filename string, storage interface{}, checksums ...gox.Checksum) File

func NewFtpFile added in v1.0.4

func NewFtpFile(filename string, ftp Ftp) File

NewFtpFile 创建一个Ftp类型的文件

func NewHttpFile added in v1.0.3

func NewHttpFile(filename string, url string, method gox.HttpMethod) File

NewHttpFile 创建Http存储文件

func NewLocal added in v1.1.1

func NewLocal(filename string) File

func NewOssFile added in v1.0.7

func NewOssFile(filename string, oss Oss) File

NewOssFile 创建一个阿里云对象存储文件

func (*File) Download added in v0.0.3

func (f *File) Download(filename string, force bool) (err error)

func (*File) UnmarshalJSON added in v1.0.3

func (f *File) UnmarshalJSON(data []byte) (err error)

func (*File) Upload added in v0.0.3

func (f *File) Upload(filename string) (err error)

type FileType added in v1.0.3

type FileType string

FileType 文件类型

const (
	// FileTypeHttp Http存储
	FileTypeHttp FileType = "http"
	// FileTypeOss 阿里云对象存储
	FileTypeOss FileType = "oss"
	// FileTypeCos 腾讯云对象存储
	FileTypeCos FileType = "cos"
	// FileTypeFtp Ftp存储
	FileTypeFtp FileType = "ftp"
	// FileTypeLocalFile 本地存储
	FileTypeLocalFile FileType = "local"
)

type Ftp

type Ftp struct {
	// 地址
	Addr string `json:"addr" validate:"required"`
	// 用户名
	Username string `json:"username" validate:"required"`
	// 密码
	Password string `json:"password" validate:"required"`
	// contains filtered or unexported fields
}

Ftp Ftp存储

func (Ftp) Download added in v1.0.4

func (f Ftp) Download(srcFilename string, destFilename string) (err error)

func (Ftp) Upload added in v1.0.4

func (f Ftp) Upload(destFilename string, srcFilename string) (err error)

type Http added in v1.0.3

type Http struct {
	// 访问地址
	Url string `json:"url"`
	// 方法
	Method gox.HttpMethod `json:"method"`
}

Http Http存储

func (*Http) Download added in v1.0.3

func (h *Http) Download(_ string, destFilename string) (err error)

func (*Http) Upload added in v1.0.3

func (h *Http) Upload(_ string, srcFilename string) (err error)

type Local added in v1.1.1

type Local struct{}

Local 本地文件

func (*Local) Download added in v1.1.1

func (l *Local) Download(srcFilename string, destFilename string) (err error)

func (*Local) Upload added in v1.1.1

func (l *Local) Upload(_ string, _ string) (err error)

type Oss

type Oss struct {
	// 端点
	Endpoint string `json:"endpoint"`
	// 桶名称
	Bucket string `json:"bucket"`
	// 授权
	AccessKey string `json:"accessKey"`
	SecretKey string `json:"secretKey"`
}

Oss 阿里云Oss存储

func (Oss) Download added in v1.0.7

func (o Oss) Download(srcFilename string, destFilename string) (err error)

func (Oss) Upload added in v1.0.7

func (o Oss) Upload(destFilename string, srcFilename string) (err error)

type Transfer added in v1.0.4

type Transfer interface {
	Uploader
	Downloader
}

Transfer 数据交换

type Uploader added in v1.0.3

type Uploader interface {
	// Upload 上传文件
	Upload(destFilename string, srcFilename string) (err error)
}

Uploader 上传

Jump to

Keyboard shortcuts

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