http

package
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Download2Memory

func Download2Memory(url string) ([]byte, error)

Download2Memory https://stackoverflow.com/a/21351456/9935654

Example
dataBytes, err := Download2Memory("https://www.google.com.tw/")
if err != nil {
	panic(err)
}
fmt.Println(len(dataBytes) > 0)
Output:

true

func DownloadFile

func DownloadFile[T *os.File | string](out T, url string) (err error)

DownloadFile https://stackoverflow.com/a/33853856/9935654

Example

Output support string or os.File both OK!

// Output type: string
if err := DownloadFile("temp.html", "https://www.google.com.tw/"); err != nil {
	panic(err)
}

// Output type: writer
writer, err := os.Create("temp2.html")
if err != nil {
	panic(err)
}
if err = DownloadFile(writer, "https://www.google.com.tw/"); err != nil {
	panic(err)
}

func DownloadFileWithTimeout added in v2.2.0

func DownloadFileWithTimeout[T *os.File | string](out T, url string, timeout time.Duration) (err error)
Example
// Output type: string
if err := DownloadFileWithTimeout("temp.html", "https://www.google.com.tw/", 5*time.Second); err != nil {
	panic(err)
}

// Output type: writer
writer, err := os.Create("temp2.html")
if err != nil {
	panic(err)
}
if err = DownloadFileWithTimeout(writer, "https://www.google.com.tw/", 5*time.Second); err != nil {
	panic(err)
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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