https://github.com/flopp/go-getfile
Go module to download files
https://github.com/flopp/go-getfile
Last synced: about 1 year ago
JSON representation
Go module to download files
- Host: GitHub
- URL: https://github.com/flopp/go-getfile
- Owner: flopp
- License: mit
- Created: 2024-09-28T10:40:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-13T11:30:26.000Z (about 1 year ago)
- Last Synced: 2025-03-13T12:31:54.264Z (about 1 year ago)
- Language: Go
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-getfile
Go module to download files
```go
// Create a getfile client
client := getfile.NewClient()
// Use a custom user agent
client.SetUserAgent("my-user-agent")
// Set a delay, e.g. duration to wait before each download
client.SetDelay(1 * time.Second)
// The free eBook "An Introduction to Programming in Go"
url := "https://www.golang-book.com/public/pdf/gobook.pdf"
targetFile := "gobook.pdf"
// Download file from url,
// overwrite existing target file
if err := client.Get(url, targetFile); err != nil {
fmt.Printf("Download failed: %v\n", err)
}
// Download file from url,
// but only if the target file doesn't exist already
if err := client.GetIfNotExists(url, targetFile); err != nil {
fmt.Printf("Download failed: %v\n", err)
}
// Downfile file from url,
// but only if the target files doesn't exist already or
// it is older than the given time duration (24 hours)
if err := client.GetIfOutdated(url, targetFile, 24 * time.Hour); err != nil {
fmt.Printf("Download failed: %v\n", err)
}
```