favicon

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package favicon provides a favicon downloader

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Download

func Download(ctx context.Context, host string, opts Options) (image.Image, error)

Download tries to download the favicon with highest resolution for the specified host By default it looks into the standard locations - http://<host>/apple-touch-icon.png - http://<host>/favicon.ico - http://<host>/favicon.png Alternatively a third-party service can be used via the Service option. Example: // Use the DuckDuckGo service

ddg := func(host string) string  {
	return fmt.Sprintf("https://icons.duckduckgo.com/ip3/%s.ico", host)
}
img, err := favicon.Download(e.ctx, host, favicon.Options{
	ForceMinSize: true,
	Service: ddg,
})

Types

type Options

type Options struct {
	// Client is http.Client used to download the favicon. Leave nil to use the
	// http.Default with a timeout of 10 seconds
	Client *http.Client
	// MinSize is the min size of the favicon to be considered valid.
	// favicon smaller than minSize will be ignored unless ForceMinSize is true
	MinSize int
	// ForceMinSize when true will force to return a favicon even if its size is
	// smaller than MinSize
	ForceMinSize bool
	Service      Service
}

type Service

type Service func(host string) string

Jump to

Keyboard shortcuts

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