ship

package
v0.0.0-...-651feb0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WhenInspect = iota + 1
	WhenDownload
)
View Source
const (
	AuthHeader = "auth"
)

Variables

View Source
var Version = "0.0.0"

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(opt ClientOption) (*Client, error)

Don't set FetcherOption.ResponsePreInspector, it will be overwritten

func (*Client) Delete

func (c *Client) Delete(remoteFile string) error

func (*Client) Get

func (c *Client) Get(concurrency int, remoteFile string, localFile string, hook func(beforeDownload bool, supported bool, length int64, n int)) error

Get remote file to local if localFile is empty, then use remoteFile

func (*Client) GetDeleteFileURL

func (c *Client) GetDeleteFileURL(remoteFile string) string

func (*Client) GetDownloadFileURL

func (c *Client) GetDownloadFileURL(remoteFile string) string

func (*Client) GetListURL

func (c *Client) GetListURL() string

func (*Client) GetPingURL

func (c *Client) GetPingURL() string

func (*Client) GetServerURL

func (c *Client) GetServerURL() *url.URL

return clone

func (*Client) GetUploadFileURL

func (c *Client) GetUploadFileURL(remoteFile string, taskID ...string) string

func (*Client) List

func (c *Client) List(cb func(info *FileInfo)) error

func (*Client) Ping

func (c *Client) Ping() (time.Duration, error)

Determine if the serverURL is available

func (*Client) Put

func (c *Client) Put(concurrency int, overwrite bool, localFile string, remoteFile string, hook func(beforeUpload bool, info UploadInfo, n int)) error

func (*Client) SetAuth

func (c *Client) SetAuth(s string, direct ...bool)

if direct, then not hash

type ClientOption

type ClientOption struct {
	Auth string
	// if path not ends with /, then auto append it
	ServerURL string
	FetcherOption
}

type Fetcher

type Fetcher struct {
	Header http.Header
	// contains filtered or unexported fields
}

Concurrent HTTP downloader

func NewFetcher

func NewFetcher(option FetcherOption) (*Fetcher, error)

func (*Fetcher) Do

func (fetcher *Fetcher) Do(req *http.Request) (*http.Response, error)

send request via Fetcher.client, Fetcher.Header will be merged

func (*Fetcher) Download

func (fetcher *Fetcher) Download(url string, option *FetcherDownloadOption) error

Download and auto inspect

func (*Fetcher) DownloadWithManual

func (fetcher *Fetcher) DownloadWithManual(url string, supported bool, length int64, option *FetcherDownloadOption) (fatalErr error)

Download with specified inspect result

func (*Fetcher) Inspect

func (fetcher *Fetcher) Inspect(url string) (supported bool, length int64, err error)

Determine if a slice download is supported

type FetcherDownloadOption

type FetcherDownloadOption struct {
	Context     context.Context
	Concurrency int
	// include first
	Retry int
	// length is total body length, if length is -1, it is unknown
	Handler func(index int, start, end, length int64, r io.Reader, ctx context.Context) error
}

type FetcherOption

type FetcherOption struct {
	InsecureSkipVerify   bool
	DisallowRedirects    bool
	ProxyURL             string
	ResponsePreInspector func(when int, resp *http.Response) error
}

type FileInfo

type FileInfo struct {
	// value of time.Time.Unix()
	ModTime int64
	Name    string
	Size    int64
}

func (*FileInfo) Dump

func (info *FileInfo) Dump() ([]byte, error)

func (*FileInfo) Load

func (info *FileInfo) Load(bs []byte) error

type FileWriter

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

func NewFileWriter

func NewFileWriter(name string) (*FileWriter, error)

func (*FileWriter) Close

func (fh *FileWriter) Close() error

func (*FileWriter) Handler

func (fw *FileWriter) Handler(index int, start, end, length int64, r io.Reader, ctx context.Context) error

func (*FileWriter) OnWrite

func (fh *FileWriter) OnWrite(cb func(n int, index int, start, end, length int64))

func (*FileWriter) Truncate

func (fh *FileWriter) Truncate(size int64) error

func (*FileWriter) WrittenN

func (fh *FileWriter) WrittenN() int64

type Service

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

func NewService

func NewService(option ServiceOption) *Service

func (*Service) ServeHTTP

func (srv *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

routes(if prefix == "/"):

ping: GET /ping

list: GET /list

upload: POST/PUT /upload?path=<path>

delete: DELETE /delete?path=<path>

download: GET/HEAD /download?path=<path>

func (*Service) SetAuth

func (srv *Service) SetAuth(s string, direct ...bool)

if direct, then not hash

type ServiceOption

type ServiceOption struct {
	// if empty, no authentication
	Auth string
	// default "/", if not ends with "/" and starts with "/", then auto fix it
	URLPathPrefix string
	// default "./"
	Root string
}

type UploadInfo

type UploadInfo struct {
	// server provide (relative path to root)
	Path string
	// server provide
	TaskID string
	// server provide
	SliceCount int64

	// client provide
	TotalSize int64
	// client provide, maybe server modify
	SliceSize int64
	// client provide
	Hash string
	// client provide
	Overwrite bool
}

Jump to

Keyboard shortcuts

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