makelink

package
v0.6.18 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func StyleList

func StyleList() string

StyleList returns supported style names.

Types

type Link struct {
	URL         string `json:"url,omitempty"`
	Location    string `json:"location,omitempty"`
	Canonical   string `json:"canonical,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
}

Link stores metadata of a URL.

func New

func New(ctx context.Context, urlStr, userAgent string) (link *Link, err error)

New fetches URL metadata and returns a Link instance.

Example
link, err := New(context.Background(), "https://git.io/vFR5M", "")
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(link.Encode(StyleMarkdown))

func (*Link) CanonicalURL

func (lnk *Link) CanonicalURL() string

CanonicalURL returns the canonical URL when available.

func (*Link) Encode

func (lnk *Link) Encode(t Style) io.Reader

Encode encodes Link in the requested style.

func (*Link) String

func (lnk *Link) String() string

String returns Link as JSON text.

func (*Link) TitleName

func (lnk *Link) TitleName() string

TitleName returns the display title.

type Style

type Style int

Style represents a link output style.

const (
	// StyleUnknown is an unknown link style.
	StyleUnknown Style = iota
	// StyleMarkdown is markdown style.
	StyleMarkdown
	// StyleWiki is wiki style.
	StyleWiki
	// StyleHTML is HTML anchor style.
	StyleHTML
	// StyleCSV is CSV data format.
	StyleCSV
	// StyleJSON is JSON format.
	StyleJSON
)

func GetStyle

func GetStyle(s string) (Style, error)

GetStyle returns a Style from its string representation.

func (Style) String

func (t Style) String() string

Jump to

Keyboard shortcuts

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