util

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Standard           = "STANDARD"
	StandardIA         = "STANDARD_IA"
	IntelligentTiering = "INTELLIGENT_TIERING"
	Archive            = "ARCHIVE"
	DeepArchive        = "DEEP_ARCHIVE"

	MAZStandard           = "MAZ_STANDARD"
	MAZStandardIA         = "MAZ_STANDARD_IA"
	MAZIntelligentTiering = "MAZ_INTELLIGENT_TIERING"
	MAZArchive            = "MAZ_ARCHIVE"
)
View Source
const (
	AesKey       = "coscli-secret"
	AesBlockSize = 16
)
View Source
const (
	ECB = 1
	CBC = 2
)

Variables

This section is empty.

Functions

func CalculateHash

func CalculateHash(path string, hashType string) (h string, b string)

func CreateClient

func CreateClient(config *Config, param *Param, bucketIDName string) *cos.Client

根据函数参数创建客户端

func CreateURL

func CreateURL(idName string, protocol string, endpoint string) *cos.BaseURL

根据函数参数生成URL

func DecryptSecret

func DecryptSecret(encode string) (decryptStr string, err error)

func DownloadPathFixed

func DownloadPathFixed(localPath string, cosPath string) (string, string, error)

func EncryptSecret

func EncryptSecret(src string) (encode string, err error)

func FormatSize

func FormatSize(b int64) string

func GenBucketURL

func GenBucketURL(bucketIDName string, protocol string, endpoint string) string

func GenCiURL

func GenCiURL(bucketIDName string, protocol string, endpoint string) string

func GenServiceURL

func GenServiceURL(protocol string, endpoint string) string

func GenURL

func GenURL(config *Config, param *Param, bucketName string) *cos.BaseURL

根据配置文件生成URL

func GetBucketsList

func GetBucketsList(c *cos.Client, limit int, include string, exclude string) (buckets []cos.Bucket)

func GetLocalFilesList

func GetLocalFilesList(localPath string, include string, exclude string) (dirs []string, files []string)

func GetLocalFilesListRecursive

func GetLocalFilesListRecursive(localPath string, include string, exclude string) (files []string)

func GetObjectsList

func GetObjectsList(c *cos.Client, prefix string, limit int, include string, exclude string) (dirs []string, objects []cos.Object)

func GetObjectsListForLs

func GetObjectsListForLs(c *cos.Client, prefix string, limit int, include string, exclude string,
	marker string) (dirs []string,
	objects []cos.Object, isTruncated bool, nextMaker string)

func GetObjectsListIterator

func GetObjectsListIterator(c *cos.Client, prefix, marker string, include, exclude string) (objects []cos.Object, isTruncated bool, nextMarker string)

func GetObjectsListRecursive

func GetObjectsListRecursive(c *cos.Client, prefix string, limit int, include string, exclude string) (objects []cos.Object)

func GetObjectsListRecursiveForLs

func GetObjectsListRecursiveForLs(c *cos.Client, prefix string, limit int, include string, exclude string,
	marker string) (objects []cos.Object, isTruncated bool, nextMarker string)

func IsCosPath

func IsCosPath(path string) bool

func MatchBucketPattern

func MatchBucketPattern(buckets []cos.Bucket, pattern string, include bool) []cos.Bucket

func MatchCosPattern

func MatchCosPattern(objects []cos.Object, pattern string, include bool) []cos.Object

func MatchPattern

func MatchPattern(strs []string, pattern string, include bool) []string

func MultiDownload

func MultiDownload(c *cos.Client, bucketName, cosDir, localDir, include, exclude string, op *DownloadOptions)

func MultiUpload

func MultiUpload(c *cos.Client, localDir, bucketName, cosDir, include, exclude string, op *UploadOptions)

func NewClient

func NewClient(config *Config, param *Param, bucketName string) *cos.Client

根据桶别名,从配置文件中加载信息,创建客户端

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.

func ParsePath

func ParsePath(url string) (bucketName string, path string)

func ShowHash

func ShowHash(c *cos.Client, path string, hashType string) (h string, b string)

func SingleDownload

func SingleDownload(c *cos.Client, bucketName, cosPath, localPath string, op *DownloadOptions) error

func SingleUpload

func SingleUpload(c *cos.Client, localPath, bucketName, cosPath string, op *UploadOptions)

func Statistic

func Statistic(objects []cos.Object)

func SyncMultiDownload

func SyncMultiDownload(c *cos.Client, bucketName, cosDir, localDir, include, exclude string, op *DownloadOptions)

func SyncMultiUpload

func SyncMultiUpload(c *cos.Client, localDir, bucketName, cosDir, include, exclude string, op *UploadOptions)

func SyncSingleDownload

func SyncSingleDownload(c *cos.Client, bucketName, cosPath, localPath string, op *DownloadOptions,
	cosLastModified string) error

func SyncSingleUpload

func SyncSingleUpload(c *cos.Client, localPath, bucketName, cosPath string, op *UploadOptions)

func UploadPathFixed

func UploadPathFixed(localPath string, cosPath string) (string, string)

Types

type AesTool

type AesTool struct {
	// 128 192  256位的其中一个 长度 对应分别是 16 24  32字节长度
	Key       []byte
	BlockSize int
	Mode      int
}

AES ECB模式的加密解密

func NewAesTool

func NewAesTool(key []byte, blockSize int, mode int) *AesTool

func (*AesTool) Decrypt

func (this *AesTool) Decrypt(src []byte) (res []byte, err error)

func (*AesTool) Encrypt

func (this *AesTool) Encrypt(src []byte) ([]byte, error)

type BaseCfg

type BaseCfg struct {
	SecretID     string `yaml:"secretid"`
	SecretKey    string `yaml:"secretkey"`
	SessionToken string `yaml:"sessiontoken"`
	Protocol     string `yaml:"protocol"`
}

type Bucket

type Bucket struct {
	Name     string `yaml:"name"`
	Alias    string `yaml:"alias"`
	Region   string `yaml:"region"`
	Endpoint string `yaml:"endpoint"`
}

func FindBucket

func FindBucket(config *Config, bucketName string) (Bucket, int, error)

type Config

type Config struct {
	Base    BaseCfg  `yaml:"base"`
	Buckets []Bucket `yaml:"buckets"`
}

type CosListener

type CosListener struct {
}

func (*CosListener) ProgressChangedCallback

func (l *CosListener) ProgressChangedCallback(event *cos.ProgressEvent)

type DownloadOptions

type DownloadOptions struct {
	RateLimiting float32
	PartSize     int64
	ThreadNum    int
	SnapshotDb   *leveldb.DB
	SnapshotPath string
}

type Meta

type Meta struct {
	CacheControl       string
	ContentDisposition string
	ContentEncoding    string
	ContentType        string
	ContentMD5         string
	ContentLength      int64
	ContentLanguage    string
	Expires            string
	// 自定义的 x-cos-meta-* header
	XCosMetaXXX *http.Header
	MetaChange  bool
}

func MetaStringToHeader

func MetaStringToHeader(meta string) (result Meta, err error)

type Param

type Param struct {
	SecretID     string
	SecretKey    string
	SessionToken string
	Endpoint     string
}

type UploadInfo

type UploadInfo struct {
	Key       string `xml:"Key,omitempty"`
	UploadID  string `xml:"UploadId,omitempty"`
	Initiated string `xml:"Initiated,omitempty"`
}

func GetUploadsList

func GetUploadsList(c *cos.Client, prefix string, limit int, include string, exclude string) (dirs []string, uploads []UploadInfo)

疑似无法返回正确结果 res.CommonPrefix无法正确获得

func GetUploadsListRecursive

func GetUploadsListRecursive(c *cos.Client, prefix string, limit int, include string, exclude string) (uploads []UploadInfo)

func MatchUploadPattern

func MatchUploadPattern(uploads []UploadInfo, pattern string, include bool) []UploadInfo

type UploadOptions

type UploadOptions struct {
	StorageClass string
	RateLimiting float32
	PartSize     int64
	ThreadNum    int
	Meta         Meta
	SnapshotDb   *leveldb.DB
	SnapshotPath string
}

Jump to

Keyboard shortcuts

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