besticon

package
v0.0.0-...-639eac9 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package besticon includes functions finding icons for a given web site.

Index

Constants

View Source
const VersionString = "v3.14.0"

Version string, same as VERSION, generated my Make

Variables

View Source
var BuildDate string // set via ldflags on Make

Functions

func MainColorForIcons

func MainColorForIcons(icons []Icon) *color.RGBA

func NewDefaultHTTPClient

func NewDefaultHTTPClient() *http.Client

func NewDefaultHTTPTransport

func NewDefaultHTTPTransport(userAgent string) http.RoundTripper

Types

type Besticon

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

Besticon is the main interface to the besticon package.

func New

func New(opts ...Option) *Besticon

New returns a new Besticon instance.

func (*Besticon) CacheEnabled

func (b *Besticon) CacheEnabled() bool

func (*Besticon) Get

func (b *Besticon) Get(urlstring string) (*http.Response, error)

func (*Besticon) GetBodyBytes

func (b *Besticon) GetBodyBytes(r *http.Response) ([]byte, error)

func (*Besticon) GetCacheStats

func (b *Besticon) GetCacheStats() groupcache.CacheStats

GetCacheStats returns cache statistics.

func (*Besticon) NewIconFinder

func (b *Besticon) NewIconFinder() *IconFinder

type Icon

type Icon struct {
	URL       string `json:"url"`
	Width     int    `json:"width"`
	Height    int    `json:"height"`
	Format    string `json:"format"`
	Bytes     int    `json:"bytes"`
	Error     error  `json:"error"`
	Sha1sum   string `json:"sha1sum"`
	ImageData []byte `json:",omitempty"`
}

Icon holds icon information.

func (*Icon) Image

func (ico *Icon) Image() (*image.Image, error)

type IconFinder

type IconFinder struct {
	FormatsAllowed  []string
	HostOnlyDomains []string
	// contains filtered or unexported fields
}

func (*IconFinder) FetchIcons

func (f *IconFinder) FetchIcons(url string) ([]Icon, error)

func (*IconFinder) IconInSizeRange

func (f *IconFinder) IconInSizeRange(r SizeRange) *Icon

func (*IconFinder) Icons

func (f *IconFinder) Icons() []Icon

func (*IconFinder) MainColorForIcons

func (f *IconFinder) MainColorForIcons() *color.RGBA

type Logger

type Logger interface {
	LogError(err error)
	// LogResponse is called when an HTTP request has been executed. The duration is the time it took to execute the
	// request. When error is nil, the response is the response object. Otherwise, the response is nil.
	LogResponse(req *http.Request, resp *http.Response, duration time.Duration, err error)
}

func NewDefaultLogger

func NewDefaultLogger(w io.Writer) Logger

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithCache

func WithCache(sizeInMB int64) Option

func WithDefaultFormats

func WithDefaultFormats(formats ...string) Option

WithDefaultFormats sets the default accepted formats.

func WithDiscardImageBytes

func WithDiscardImageBytes(discardImageBytes bool) Option

WithDiscardImageBytes sets whether to discard image bodies.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets the http client to use for requests.

func WithLogger

func WithLogger(logger Logger) Option

WithLogger sets the logger to use for logging.

type SizeRange

type SizeRange struct {
	Min     int
	Perfect int
	Max     int
}

SizeRange represents the desired icon dimensions

func ParseSizeRange

func ParseSizeRange(s string, maxIconSize int) (*SizeRange, error)

ParseSizeRange parses a string like 60..100..200 into a SizeRange

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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