preview

package
v0.0.0-...-7e2b890 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package preview fetches OpenGraph/link previews for URLs with SSRF protection (private/loopback/link-local destinations are refused), strict timeouts, redirect and body-size limits, and HTML-only parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstLink(text string) string

FirstLink returns the first http(s) URL in text that is not a direct media link (image/video/audio), suitable for an OpenGraph preview.

Types

type Fetcher

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

Fetcher retrieves previews. The zero value is not usable; use New.

func New

func New() *Fetcher

func (*Fetcher) Fetch

func (f *Fetcher) Fetch(ctx context.Context, rawURL string) (Result, error)

Fetch retrieves and parses a preview for rawURL.

type Result

type Result struct {
	Title       string
	Description string
	Image       string
	SiteName    string
}

Result is a fetched preview.

func (Result) Has

func (r Result) Has() bool

Has reports whether the result carries anything worth showing.

Jump to

Keyboard shortcuts

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