GCPStorage

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MD5file added in v2.0.1

func MD5file(url string) (string, error)

MD5file

func MD5fileBytes added in v2.0.1

func MD5fileBytes(url string) (hash []byte, err error)

Types

type Bucket

type Bucket struct {
	// contains filtered or unexported fields
}

func (*Bucket) Attrs

func (b *Bucket) Attrs(filePath string) (attrs *storage.ObjectAttrs, err error)

Attrs returns the metadata for the bucket.

func (*Bucket) CopyFile

func (b *Bucket) CopyFile(src, dst string) error

CopyFile copy cloud storage file to another dst

func (*Bucket) CopyFolder

func (b *Bucket) CopyFolder(srcFolder, dstFolder string, multiple bool) error

CopyFolder copy cloud storage folder to another dst

func (*Bucket) Delete

func (b *Bucket) Delete(filePath string) error

Delete storage file from the current bucket

func (*Bucket) DeleteFolder

func (b *Bucket) DeleteFolder(folder string) error

DeleteFolder delete all files under folder

func (*Bucket) DeleteOldFiles

func (b *Bucket) DeleteOldFiles(folder string, fileAge time.Duration) error

DeleteOldFiles delete files from folder based on their age, time from created date

func (*Bucket) Download

func (b *Bucket) Download(src, dst string) error

Download file from source (src) to local destination (dst)

func (*Bucket) Exists

func (b *Bucket) Exists(filePath string) (bool, error)

Exists check if file exists

func (*Bucket) GetFileReader

func (b *Bucket) GetFileReader(object string, optionalBucket ...string) (reader io.Reader, err error)

GetFileReader get file reader from gcp bucket

func (*Bucket) GetMeta

func (b *Bucket) GetMeta(src string, optionalBucket ...string) (Meta, error)

GetMeta get size

func (*Bucket) GetSignedURL

func (b *Bucket) GetSignedURL(objectPath string, duration time.Duration, optionalBucket ...string) (string, error)

GetSignedURL get signed url with expire time

func (*Bucket) Init

func (b *Bucket) Init(bucket string)

Init storage instance

func (*Bucket) List

func (b *Bucket) List(prefix string, limit int) (files []string, err error)

List all files in a bucket with a prefix prefix can be a folder, if prefix is empty string the function will return all files in the bucket limit is number of files to retrive, 0 means all

func (*Bucket) MD5

func (b *Bucket) MD5(filePath string) (md5String string, err error)

MD5 get the md5 checksum of a file in a bucket

func (*Bucket) MakePublic

func (b *Bucket) MakePublic(filePath string) (downloadURL string, err error)

MakePublic make file public (readonly) and retrive the download url

func (*Bucket) ReadFile

func (b *Bucket) ReadFile(filepath string, obj interface{}) (err error)

ReadFile into object

func (*Bucket) Size

func (b *Bucket) Size(filePath string) (size int64, err error)

Size get the size of the file in int64

func (*Bucket) Upload

func (b *Bucket) Upload(localFile, dst string) error

Upload local file to the current bucket

func (*Bucket) UploadFromReader

func (b *Bucket) UploadFromReader(reader io.Reader, dst string, optionalBucket ...string) error

UploadFromReader upload from reader to GCP file

func (*Bucket) UploadVerify added in v2.0.1

func (b *Bucket) UploadVerify(localFile, dst string) error

UploadVerify local file to the current bucket and perform checksum after uploading

type Meta

type Meta struct {
	MD5         string
	Size        int64
	SizeStr     string
	LastUpdate  time.Time
	Created     time.Time
	ContentType string
}

Meta holds important meta about a file

Jump to

Keyboard shortcuts

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