sherlock

package module
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 2 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

🔍 Sherlock

Illustration of Sherlock Holmes and Watson in a train car, by Sidney Paget. From Arthur Conan Doyle's 1892 book 'The Adventure of Silver Blaze'

Go Reference Version Build Status Go Report Card Codecov

Relentless Metadata Inspector

Sherlock is a Go library that inspects a URL for any and all available metadata, pulling from whatever formats are available, and returning a single merged answer.

The goal is to have a standard interface into all web content, regardless of competing data standards.

The work happens in the sub-packages, and they answer two different questions. metadata asks "what is this page?" and returns an oEmbed-adjacent Preview. The middleware stack asks "what ActivityStreams document is at this URL?" and answers as a Hannibal streams.Client. This root package holds only what both sides share.

Supported Formats

The metadata engine fetches once, parses once, and merges every in-page format it finds by a fixed precedence.

✅ ActivityPub / ActivityStreams

✅ Open Graph

✅ Twitter Cards

✅ oEmbed — lazily, only when the page suggests it could help

✅ Native HTML signals — <title>, <meta name="description">, rel=canonical, rel=alternate

Middleware and Rewriters

The ActivityStreams half of Sherlock is a stack of client middlewares. Most just resolve a format, but a few rewrite an identifier into something the rest of the stack can resolve, or substitute a placeholder for a missing document. Each is its own subpackage with its own README and placement rules.

  • activitypub — loads ActivityPub documents directly from their canonical URLs. This is the bottom of the stack, and the only layer that fetches.

  • webfinger — recognizes @user@host handles and resolves them to a canonical ActivityPub URL for the rest of the stack to load. The rewriters below all hand off to it.

  • bridgyfed — rewrites a Bluesky-looking handle (alice.bsky.social) into a WebFinger handle on Bridgy Fed, so Bluesky accounts resolve as ActivityPub actors.

  • tagspub — rewrites a #hashtag into a WebFinger handle on tags.pub, so hashtags resolve to ActivityPub collections.

  • tombstone — turns a "Gone" (HTTP 410) response into a synthetic ActivityStreams Tombstone, so deleted objects resolve to a stable placeholder instead of an error.

Inspecting a webpage

metadata.Get fetches a URL once and extracts every in-page format from a single parsed tree, merged by a fixed precedence (ActivityStreams → Open Graph → Twitter Cards → oEmbed → HTML natives) into an oEmbed-adjacent metadata.Preview — title, description, canonical URL, thumbnail, embed, provider, authors, dates.

preview, err := metadata.Get(ctx, "https://example.com/article",
    metadata.WithUserAgent("my-app/1.0"),
)
if err != nil {
    return err
}

fmt.Println(preview.Title, preview.Description)

// Groups are filled whole from one source, or not at all -- check before use.
if preview.Thumbnail != nil {
    fmt.Println(preview.Thumbnail.URL, preview.Thumbnail.Alt)
}

Options carry the fetch policy. Private and loopback addresses are refused by default as an SSRF guard, and response bodies are capped:

preview, err := metadata.Get(ctx, "https://my-lan-host.local/article",
    metadata.WithAllowPrivateIPs(true),
    metadata.WithMaxBodySize(2 * 1024 * 1024),
)

The oEmbed endpoint (the only extra network hop) is called lazily — only when a registry match or player tags suggest an embed, or when fields oEmbed could fill are still empty. Provider embed HTML never enters the model raw: it is classified by oembed's Embed() into a rebuilt iframe, sandboxed markup, or nothing. Sandboxed markup is off by default; opt in with WithAllowSandboxEmbeds(true) if your renderer places Embed.HTML inside a sandboxed iframe.

The engine never imports ActivityStreams types — the package boundary enforces the layering.

Loading an ActivityStreams document

Each middleware implements the Hannibal streams.Client interface, so a stack of them can serve as the HTTP client for that ActivityPub library. Order matters, and each subpackage's README states its own placement rule.

// Innermost first: each layer wraps the one below it.
client := tagspub.New(
    bridgyfed.New(
        webfinger.New(
            tombstone.New(
                activitypub.New(
                    activitypub.WithUserAgent("my-app/1.0"),
                ),
            ),
        ),
    ),
)

document, err := client.Load("@alice@example.social")

Per-call options travel down the stack as ...any, and the bottom layer keeps the remote.Option values it recognizes. Anything else is ignored.

Signing outbound requests

AuthorizedFetch is a remote.Option that signs a request according to the ActivityPub Authorized Fetch convention. The activitypub middleware applies it for you when given a key pair; pass it directly for any other fetch that needs a signature.

txn := remote.Get(url).
    With(sherlock.AuthorizedFetch(publicKeyID, privateKey))

Image Credit

The banner is an illustration by Sidney Paget for The Adventure of Silver Blaze (Arthur Conan Doyle, 1892). The work is in the public domain.

No Warranty

This software is provided as-is, without any warranty of any kind. Use it at your own risk.

Pull Requests Welcome

I'm trying to make Sherlock the best it can be, and your help is greatly appreciated. If you find a bug or have an idea for a new feature, please open an issue or submit a pull request. We're all in this together! 🔍

Documentation

Overview

Package sherlock inspects a URL for any and all available metadata, using as many methods as possible: ActivityStreams, Open Graph, Twitter Cards, oEmbed, and native HTML signals.

The work happens in the sub-packages. Webpage metadata extraction is the metadata sub-package, whose Get function fetches a URL once and returns an oEmbed-adjacent Preview. ActivityStreams loading is a stack of client middlewares -- activitypub, tombstone, webfinger, bridgyfed, and tagspub -- each implementing hannibal's streams.Client interface.

This root package holds only what those sub-packages and their callers share: AuthorizedFetch, which signs an outbound request according to the ActivityPub Authorized Fetch convention, and the address classifiers that decide whether a value looks like something Sherlock could resolve.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthorizedFetch added in v0.8.0

func AuthorizedFetch(publicKeyID string, privateKey crypto.PrivateKey) remote.Option

AuthorizedFetch is a remote.Option that signs all outbound requests according to the ActivityPub "Authorized Fetch" convention: https://funfedi.dev/testing_tools/http_signatures/

func IsValidAddress added in v0.6.5

func IsValidAddress(address string) bool

IsValidAddress returns TRUE for values that Sherlock THINKS it should be able to process: @username@host.tld and https://host.tld/username addresses.

func IsValidUsername added in v0.8.19

func IsValidUsername(username string) bool

IsValidUsername returns TRUE if the value is at least three characters of letters, digits, or underscores.

Types

This section is empty.

Directories

Path Synopsis
Package activitypub provides a Sherlock client middleware that loads ActivityPub/ActivityStream documents directly from their canonical URLs.
Package activitypub provides a Sherlock client middleware that loads ActivityPub/ActivityStream documents directly from their canonical URLs.
Package bridgyfed is a Sherlock adapter that attempts to translate a Bluesky-looking value into an ActivityPub actor via Bridgy Fed.
Package bridgyfed is a Sherlock adapter that attempts to translate a Bluesky-looking value into an ActivityPub actor via Bridgy Fed.
Package metadata fetches a web page once and extracts an oEmbed-adjacent Preview from every source the page carries: ActivityStreams, Open Graph, Twitter Cards, oEmbed, and HTML natives.
Package metadata fetches a web page once and extracts an oEmbed-adjacent Preview from every source the page carries: ActivityStreams, Open Graph, Twitter Cards, oEmbed, and HTML natives.
Package tagspub attempts to translate a tag-looking value into a tags.pub ActivityPub actor
Package tagspub attempts to translate a tag-looking value into a tags.pub ActivityPub actor
Package tombstone is a Sherlock client middleware that turns a "Gone" (HTTP 410) response into a synthetic ActivityStreams Tombstone document.
Package tombstone is a Sherlock client middleware that turns a "Gone" (HTTP 410) response into a synthetic ActivityStreams Tombstone document.
Package webfinger identifies values that seem like usernames and uses WebFinger to try to resolve them into ActivityPub URLs
Package webfinger identifies values that seem like usernames and uses WebFinger to try to resolve them into ActivityPub URLs

Jump to

Keyboard shortcuts

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