travelagent

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package travelagent gets the suitcases to their final destination

Index

Constants

View Source
const (
	// StatusPending has not yet started
	StatusPending = iota
	// StatusInProgress is currently running
	StatusInProgress
	// StatusComplete is completed successfully
	StatusComplete
	// StatusFailed is a falure
	StatusFailed
)

Variables

This section is empty.

Functions

func BindCobra

func BindCobra(cmd *cobra.Command)

BindCobra adds the appropriate flags to use the travel agent

Types

type ErrorResponse

type ErrorResponse struct {
	Errors []string `json:"errors"`
}

ErrorResponse represents an error from the api

type Option

type Option func() (func(*TravelAgent), error)

Option is just an option for TravelAgent

func WithClient

func WithClient(c *http.Client) Option

WithClient sets the http client

func WithCmd

func WithCmd(cmd *cobra.Command) Option

WithCmd binds cobra args on

func WithCredentialBlob added in v0.20.0

func WithCredentialBlob(s string) Option

WithCredentialBlob sets the url and password from a base64 encoded json blob

func WithMetaTokenExpiration added in v0.19.0

func WithMetaTokenExpiration(d time.Duration) Option

WithMetaTokenExpiration sets the suitcase token at create

func WithPrintCurl

func WithPrintCurl() Option

WithPrintCurl prints out the curl command for each request

func WithToken

func WithToken(s string) Option

WithToken sets the token

func WithTokenExpiration added in v0.19.0

func WithTokenExpiration(d time.Duration) Option

WithTokenExpiration sets the suitcase token at create

func WithURL

func WithURL(s string) Option

WithURL sets the url from a string

func WithUniquePrefix added in v0.19.0

func WithUniquePrefix(s string) Option

WithUniquePrefix adds a unique prefix to the uploaded path

func WithUploadRetries added in v0.19.0

func WithUploadRetries(i int) Option

WithUploadRetries sets the total retries for an upload

func WithUploadRetryTime added in v0.19.0

func WithUploadRetryTime(d time.Duration) Option

WithUploadRetryTime sets the time between retries

type Response

type Response struct {
	Response *http.Response
}

Response is a good http response

type Status

type Status int

Status describes specific statuses for the updates

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

MarshalJSON handles converting the int to a string

func (Status) String

func (s Status) String() string

type StatusUpdate

type StatusUpdate struct {
	Status                 Status     `json:"status,omitempty"`
	SizeBytes              int64      `json:"size_bytes,omitempty"`
	Speed                  float64    `json:"speed,omitempty"`
	TransferredBytes       int64      `json:"transferred_bytes,omitempty"`
	PercentDone            int        `json:"percent_done,omitempty"`
	Name                   string     `json:"-"`
	StartedAt              *time.Time `json:"started_at,omitempty"`
	CompletedAt            *time.Time `json:"completed_at,omitempty"`
	MetadataCheckSum       string     `json:"metadata_checksum,omitempty"`
	Metadata               string     `json:"metadata,omitempty"`
	SuitcasectlSource      string     `json:"suitcasectl_source,omitempty"`
	SuitcasectlDestination string     `json:"suitcasectl_destination,omitempty"`
}

StatusUpdate is a little structure that gives our TravelAgent more info on where we are in the process

func NewStatusUpdate

func NewStatusUpdate(r rclone.TransferStatus) *StatusUpdate

NewStatusUpdate returns a new status update from an rclone.TransferStatus object

type StatusUpdateResponse

type StatusUpdateResponse struct {
	Messages []string `json:"messages,omitempty"`
}

StatusUpdateResponse is the actual text from a response

type TravelAgent

type TravelAgent struct {
	URL   *url.URL
	Token string

	UniquePrefix string
	// contains filtered or unexported fields
}

TravelAgent is the main object that's gonna do all this work

func New

func New(options ...Option) (*TravelAgent, error)

New returns a new TravelAgent using functional options

func (TravelAgent) StatusURL

func (t TravelAgent) StatusURL() string

StatusURL is just the web url for viewing this stuff

func (TravelAgent) Update

Update updates the status of an agent

func (TravelAgent) Upload added in v0.19.0

func (t TravelAgent) Upload(fn string, c chan rclone.TransferStatus) (int64, error)

Upload sends a file off to the cloud, given the file to upload

type TravelAgenter

type TravelAgenter interface {
	StatusURL() string
	Update(StatusUpdate) (*StatusUpdateResponse, error)
	Upload(string, chan rclone.TransferStatus) (int64, error)
}

TravelAgenter is the thing that describes what a travel agent is!

Jump to

Keyboard shortcuts

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