download

package
v1.11.13 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package download fetches remote files used by this program and the website.

Index

Constants

View Source
const (
	// UserAgent is the value of User-Agent request HEADER
	// that lets servers identify this application.
	UserAgent = "defacto2 cli"
	// RFC5322 is a HTTP-date value.
	RFC5322 = "Mon, 2 Jan 2006 15:04:05 MST"
	// DownloadPrefix header filename attachment.
	DownloadPrefix = "attachment; filename="

	ContentDisposition = "Content-Disposition"
	ContentLength      = "Content-Length"
)

Variables

This section is empty.

Functions

func CheckTime

func CheckTime(t time.Duration) time.Duration

CheckTime creates a valid time duration for use with http.Client.Timeout. The t value can be 0 or a number of seconds.

func Get

func Get(url string, timeout time.Duration) ([]byte, int, error)

PingGet connects to a URL and returns its response.

func GetSave added in v1.10.0

func GetSave(w io.Writer, name, url string) (http.Header, error)

GetSave downloads the url and saves it as the named file.

func PingFile added in v1.10.0

func PingFile(link string, timeout time.Duration) (
	code int, name string, size string, err error,
)

PingFile connects to a URL file down and returns its status code, filename and file size.

func PingHead added in v1.10.0

func PingHead(url string, timeout time.Duration) (*http.Response, error)

PingHead connects to a URL and returns its HTTP status code and status text.

func StatusColor

func StatusColor(code int, status string) string

StatusColor colours the HTTP status based on its severity.

Types

type Request

type Request struct {
	Link    string        // URL to request.
	Timeout time.Duration // Timeout duration (5 * time.Second).
	Read    []byte        // HTTP body data received.
	Code    int           // HTTP statuscode received.
	Status  string        // HTTP status received.
}

Request a HTTP download.

func (*Request) Body

func (r *Request) Body() error

Body fetches a HTTP link and returns its data and the status code.

Directories

Path Synopsis
internal
cnter
Package cnter is an optional progress counter for the remote file downloads.
Package cnter is an optional progress counter for the remote file downloads.

Jump to

Keyboard shortcuts

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