Skip to content

MeVitae/iconscraper

Repository files navigation

Icon-Scraper Package Documentation

iconscraper is a Go package that provides a robust solution to get icons from domains.

Icon Sources

Other sources

These aren't currently scraped, but might be of interest:

Usage

Get icons from multiple domains

import "github.com/MeVitae/iconscraper"

config := Config{
    SquareOnly:            true,
    TargetHeight:          128,
    MaxConcurrentRequests: 32,
    AllowSvg:              false,
}

domains := []string{"mevitae.com", "example.com", "gov.uk", "golang.org", "rust-lang.org"}

icons := iconscraper.GetIcons(config, domains)

for domain, icon := range icons {
	fmt.Println("Domain: " + domain + ", Icon URL: " + icon.URL)
}

Handle errors and warnings.

Errors related to decoding images or resources not being found on a web server (but the connection being ok) will be reported as warnings instead of errors.

By default, errors and warnings are only logged to the console. You can handle errors yourself by adding your own channel in the config, for example:

import "github.com/MeVitae/iconscraper"

config := Config{
    SquareOnly:            true,
    TargetHeight:          128,
    MaxConcurrentRequests: 32,
    AllowSvg:              false,
    Errors:                make(chan error),
}

go func(){
    for err := range config.Errors {
        // Handle err
    }
}()

domains := []string{"mevitae.com", "example.com", "gov.uk", "golang.org", "rust-lang.org"}

icons := iconscraper.GetIcons(config, domains)

for domain, icon := range icons {
	fmt.Println("Domain: " + domain + ", Icon URL: " + icon.URL)
}

Warnings can be similarly handled using the Warnings field.

Get icon from a single domain

Icons can be scraped for a single domain using GetIcon. Errors and warnings are handled in the same way.