favicons

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFaviconNotFound = errors.New("favicon not found")
View Source
var ErrInvalidFaviconExtension = errors.New("invalid favicon extension")

Functions

This section is empty.

Types

type FaviconImage

type FaviconImage struct {
	Url  string
	Hash string
	Raw  []byte
}

FaviconImage stores the url, hash and raw bytes of an image

func CreateFaviconImage

func CreateFaviconImage(url string) *FaviconImage

CreateFaviconImage outputs a FaviconImage with the specified URL or nil if the URL is an empty string.

type FaviconList

type FaviconList struct {
	Ico *FaviconImage // can be generated from png with wrapper
	Png *FaviconImage // can be generated from svg with inkscape
	Svg *FaviconImage
}

FaviconList contains the ico, png and svg icons for separate favicons

func (*FaviconList) PreProcess

func (l *FaviconList) PreProcess(convert func(in []byte) ([]byte, error)) error

PreProcess takes an input of the svg2png conversion function and outputs an error if the SVG, PNG or ICO fails to download or generate

func (*FaviconList) ProduceForExt

func (l *FaviconList) ProduceForExt(ext string) (raw []byte, contentType string, err error)

ProduceForExt outputs the bytes for the ico/png/svg icon and the HTTP Content-Type header to output.

func (*FaviconList) ProduceIco

func (l *FaviconList) ProduceIco() ([]byte, error)

ProduceIco outputs the bytes of the ico icon or an error

func (*FaviconList) ProducePng

func (l *FaviconList) ProducePng() ([]byte, error)

ProducePng outputs the bytes of the png icon or an error

func (*FaviconList) ProduceSvg

func (l *FaviconList) ProduceSvg() ([]byte, error)

ProduceSvg outputs the bytes of the svg icon or an error

type Favicons

type Favicons struct {
	// contains filtered or unexported fields
}

Favicons is a dynamic favicon generator which supports overwriting favicons

func New

func New(db *sql.DB, inkscapeCmd string) *Favicons

New creates a new dynamic favicon generator

func (*Favicons) Compile

func (f *Favicons) Compile()

Compile downloads the list of favicon mappings from the database and loads them and the target favicons into memory for faster lookups

This method makes use of the rescheduler instead of just ignoring multiple calls.

func (*Favicons) GetIcons

func (f *Favicons) GetIcons(host string) *FaviconList

GetIcons returns the favicon list for the provided host or nil if no icon is found or generated

Jump to

Keyboard shortcuts

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