uploader

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LocalObjectTypeAdded tags the local added file's tag
	LocalObjectTypeAdded = "added"

	// LocalObjectTypeChanged tags the local changed file's tag
	LocalObjectTypeChanged = "changed"
)

Variables

This section is empty.

Functions

func DetectContentType

func DetectContentType(filepath string) string

DetectContentType returns the file content-type

func DriverValidate

func DriverValidate(name string) error

DriverValidate is a func to validate driver

func MD5Hex

func MD5Hex(filepath string) string

MD5Hex returns the file md5 hash hex

Types

type Driver

type Driver interface {
	ListObjects(prefix string) ([]Object, error)
	Upload(object, rawPath string) error
	Delete(object string) error
}

Driver is the interface that must be implemented by a cloud storage driver.

func NewDriver

func NewDriver(driver DriverConfig) (Driver, error)

New is a instantiation function to find and init a upload driver.

func NewS3Uploader

func NewS3Uploader(region, endpoint, accessKey, secretKey, bucketName string) (Driver, error)

NewS3Uploader returns a new s3 uploader

type DriverConfig

type DriverConfig struct {
	Name      string `yaml:"name"`
	Region    string `yaml:"region"`
	Bucket    string `yaml:"bucket"`
	AccessKey string `yaml:"access_key"`
	SecretKey string `yaml:"secret_key"`
}

DriverConfig provides driver configuration for the uploader.

type Engine

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

Engine provides the core logic to finish the feature

func NewEngine

func NewEngine(conf EngineConfig, ud Driver) *Engine

New returns a new engine.

func (*Engine) Failed

func (e *Engine) Failed(path string, err error)

func (*Engine) Success

func (e *Engine) Success(host, path string)

func (*Engine) TailRun

func (e *Engine) TailRun(paths ...string)

TailRun run the core logic with every path.

type EngineConfig

type EngineConfig struct {
	SaveRoot  string   `yaml:"save_root"`
	VisitHost string   `yaml:"visit_host"`
	ForceSync bool     `yaml:"force_sync"`
	Excludes  []string `yaml:"excludes"`
}

EngineConfig provides core configuration for the engine.

type Object

type Object struct {
	Key      string // remote file path
	ETag     string // file md5
	FilePath string // local file path
	Type     string // local file type, added or changed
}

Object is the basic operation unit

type S3Uploader

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

S3Uploader implements the Driver base on the S3 of AWS.

func (*S3Uploader) Delete

func (u *S3Uploader) Delete(object string) (err error)

Delete deletes the object

func (*S3Uploader) ListObjects

func (u *S3Uploader) ListObjects(prefix string) ([]Object, error)

ListObjects returns some remote objects

func (*S3Uploader) Upload

func (u *S3Uploader) Upload(objectKey, filePath string) (err error)

Upload uploads the local file to the object

type Syncer

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

Syncer is the syncer to finish the logic

func NewSyncer

func NewSyncer(d Driver) *Syncer

NewSyncer returns a new syncer.

func (*Syncer) Sync

func (s *Syncer) Sync(localObjects []Object, saveRoot string) error

Sync uploads the to be upload objects to the cloud and delete the not exist remote objects

Jump to

Keyboard shortcuts

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