urlpreview

package module
v0.0.0-...-89d9964 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: MPL-2.0 Imports: 3 Imported by: 0

README

urlpreview

A library for fetching link previews in Go.

https://sourcehut.org
┗━ sourcehut - the hacker's forge
https://www.youtube.com/watch?v=dQw4w9WgXcQ
┗━ Rick Astley - Never Gonna Give You Up (Official Music Video) [3m33s] 2009-10-25 (Rick Astley) 1,234,110,921 views HD
gemini://drewdevault.com/2021/10/05/Terminal-emulation-legacy.gmi
┗━ The distant legacy of terminal emulators

License

urlpreview is licensed under the Mozilla Public License 2.0.

Documentation

Overview

Package urlpreview provides routines for fetching short snippets of information, or previews, of URLs. It implements a set of preview handlers (which handle fetching resources) and format parsers that can be used by any previewer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrBadResponse

type ErrBadResponse struct {
	Status int
}

func (ErrBadResponse) Error

func (e ErrBadResponse) Error() string

type Preview

type Preview interface {
	String() string
}

Preview is an interface for different kinds of previews. The bare minimum is the ability to get a string preview.

type PreviewHandler

type PreviewHandler interface {
	Preview(context.Context, *url.URL) (Preview, error)
}

PreviewHandler is an interface implemented by previewers. The Preview method should return a nil Preview and a nil error if it can't handle the URL.

type Previewer

type Previewer struct {
	Handlers []PreviewHandler
}

Previewer is a stack of PreviewHandler instances.

func (*Previewer) Preview

func (p *Previewer) Preview(ctx context.Context, u *url.URL) (preview Preview, err error)

Preview tries to fetch a preview of the URL using registered handlers. Any error returned by any handler is bubbled up. If no handler successfully fetched a preview, Preview returns nil as both return values.

func (*Previewer) With

func (p *Previewer) With(handler PreviewHandler) *Previewer

With adds a new PreviewHandler to the Previewer and returns itself. This method is useful for easy Previewer initialization.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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