Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CategoryBits ¶
CategoryBits is the exported wrapper around categoryBits for testing.
Types ¶
type Bing ¶
type Bing struct {
// contains filtered or unexported fields
}
Bing is a Source adapter that fetches the Bing daily wallpapers.
func NewBingWithBase ¶
NewBingWithBase creates a Bing adapter with a custom base URL for testing.
func (*Bing) Categories ¶
Categories returns the categories supported by Bing. Bing has no categories.
func (*Bing) Search ¶
func (b *Bing) Search(opts SearchOpts) ([]WallpaperResult, error)
Search fetches daily wallpapers from Bing. The query in opts is intentionally ignored — Bing always returns its curated daily images.
func (*Bing) SearchTotal ¶
func (b *Bing) SearchTotal(_ SearchOpts) (int, error)
SearchTotal returns 8 — Bing always has up to 8 daily wallpapers.
type Reddit ¶
type Reddit struct {
// contains filtered or unexported fields
}
Reddit is a Source adapter that fetches wallpapers from Reddit.
func NewRedditWithBase ¶
NewRedditWithBase creates a Reddit adapter with a custom base URL for testing.
func (*Reddit) Categories ¶
Categories returns the default subreddits available as categories.
func (*Reddit) Search ¶
func (r *Reddit) Search(opts SearchOpts) ([]WallpaperResult, error)
Search fetches wallpapers from the given subreddit.
func (*Reddit) SearchTotal ¶
func (r *Reddit) SearchTotal(_ SearchOpts) (int, error)
SearchTotal returns -1 since Reddit doesn't expose total counts.
type SearchOpts ¶
type SearchOpts struct {
Query string
Sort string
Count int
Page int
MinRes string
Categories []string
TimeRange string
Colors []string // hex colors e.g. "000000", "ffffff"
Ratios string // "landscape", "portrait", "16x9", etc.
// Subreddit is only meaningful for the reddit source.
Subreddit string
}
SearchOpts carries all parameters for a search request.
type Source ¶
type Source interface {
// Search fetches wallpapers matching opts.
Search(opts SearchOpts) ([]WallpaperResult, error)
// SearchTotal returns how many results are available server-side for the
// given opts without downloading all of them. Returns -1 if unknown.
SearchTotal(opts SearchOpts) (int, error)
// Name returns the unique slug for this source (e.g. "wallhaven").
Name() string
// NeedsKey reports whether this source requires an API key.
NeedsKey() bool
// Categories returns the list of categories supported by this source.
Categories() []string
}
Source is the interface that all wallpaper sources must implement.
type Wallhaven ¶
type Wallhaven struct {
// contains filtered or unexported fields
}
Wallhaven is a Source adapter for the Wallhaven API.
func NewWallhaven ¶
NewWallhaven creates a Wallhaven adapter. apiKey may be empty for SFW-only searches.
func NewWallhavenWithBase ¶
NewWallhavenWithBase creates a Wallhaven adapter with a custom base URL and HTTP client, intended for testing with httptest servers.
func (*Wallhaven) Categories ¶
Categories returns the categories supported by Wallhaven.
func (*Wallhaven) NeedsKey ¶
NeedsKey reports whether an API key is required. Wallhaven does not require one for SFW searches.
func (*Wallhaven) Search ¶
func (w *Wallhaven) Search(opts SearchOpts) ([]WallpaperResult, error)
Search fetches wallpapers from Wallhaven matching opts.
func (*Wallhaven) SearchTotal ¶
func (w *Wallhaven) SearchTotal(opts SearchOpts) (int, error)
SearchTotal returns the total number of matching wallpapers on the server.
type WallpaperResult ¶
type WallpaperResult struct {
ID string
Source string
PreviewURL string
FullURL string
Resolution string
Views int
Favorites int
Tags []string
}
WallpaperResult is a single wallpaper returned by a Source.
func (WallpaperResult) Filename ¶
func (r WallpaperResult) Filename() string
Filename returns a deterministic local filename for the wallpaper in the form "{source}-{id}.{ext}". Query parameters are stripped from the extension so that URLs like "…/image.png?s=abc" produce ".png".
func (WallpaperResult) MeetsMinResolution ¶
func (r WallpaperResult) MeetsMinResolution(minRes string) bool
MeetsMinResolution reports whether the wallpaper's resolution is at least minRes. If the wallpaper's own resolution is unknown (empty / unparseable), or if minRes is empty / unparseable, the function returns true so that the wallpaper is not filtered out.