Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thetardigrade/golang-cachedpagedownloader

Go package to download webpages, or access previously cached versions of them.
https://github.com/thetardigrade/golang-cachedpagedownloader

downloader go golang web-scraper web-scraping webpage-capture

Last synced: 6 days ago
JSON representation

Go package to download webpages, or access previously cached versions of them.

Awesome Lists containing this project

README

        

# golang-cachedPageDownloader

This package makes it easy to download — or access previously cached versions of — webpages.

[![Go Reference](https://pkg.go.dev/badge/github.com/theTardigrade/golang-cachedPageDownloader.svg)](https://pkg.go.dev/github.com/theTardigrade/golang-cachedPageDownloader) [![Go Report Card](https://goreportcard.com/badge/github.com/theTardigrade/golang-cachedPageDownloader)](https://goreportcard.com/report/github.com/theTardigrade/golang-cachedPageDownloader)

## Example

```golang
package main

import (
"fmt"
"time"

cachedPageDownloader "github.com/theTardigrade/golang-cachedPageDownloader"
)

const (
exampleURL = "https://google.com/"
)

func main() {
downloader, err := cachedPageDownloader.NewDownloader(&cachedPageDownloader.Options{
CacheDir: "./cache",
MaxCacheDuration: time.Minute * 5,
ShouldKeepCacheOnClose: false,
})
if err != nil {
panic(err)
}
defer downloader.Close()

// calling the function below will retrieve the content of the webpage from the internet
content, isFromCache, err := downloader.Download(exampleURL)
if err != nil {
panic(err)
}

fmt.Println(len(content))
fmt.Println(isFromCache) // false

fmt.Println("*****")

// calling the function again will retrieve the content of the webpage from our cache
content, isFromCache, err = downloader.Download(exampleURL)
if err != nil {
panic(err)
}

fmt.Println(len(content))
fmt.Println(isFromCache) // true
}
```

## Support

If you use this package, or find any value in it, please consider donating:

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/S6S2EIRL0)