hannibal

package module
v0.48.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: 7 Imported by: 3 modules, 5 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

🐘 Hannibal

Go Reference Version Build Status Go Report Card Codecov

Triumphant ActivityPub for Go

Hannibal is an experimental ActivityPub library for Go. Its goal is to be a robust, idiomatic, and thoroughly documented ActivityPub implementation that fits into your application without any magic or drama.

PLEASE USE.. *with caution

I would be honored for you to see if Hannibal works for your project. It is being used successfully in several production websites.

However, it is still subject to significant breaking changes. So, please reach out and I am happy to help you get things working in your own software. And, please be prepared for the ground to shift under your feet with newer versions.

Packages

Like the ActivityPub spec itself, Hannibal is broken into several layers:

pub - ActivityPub client/server

https://www.w3.org/TR/activitypub/

This is not an ActivityPub framework, but a simple library that easily plugs into your existing app. Add ActivityPub behaviors to your existing handlers, and send ActivityPub messages to other servers.

vocab - ActivityStreams Vocabulary

https://www.w3.org/TR/activitystreams-vocabulary/

The vocab package includes the standard ActivityStream vocabulary, including names of actions, objects and properties used in ActivityPub.

streams - ActivityStreams data structures

https://www.w3.org/TR/activitystreams-core/

The streams package contains common data structures defined in the ActivityStreams spec, notably definitions for: Document, Collection, OrderedCollection, CollectionPage, and OrderedCollectionPage. These are used by ActivityPub to send and receive multiple records in one HTTP request.

This package also includes a lightweight wrapper around generic data structures (like map[string]any and []any) that makes it easy to access data structures within an ActivityStreams/JSON-LD document.

metadata - Server-side document metadata

The metadata package holds what your server knows about a document, such as reply counts, relationships, and the current viewer's moderation labels. None of it is ever part of the document's wire value.

sigs - HTTP Signatures and Digests

https://datatracker.ietf.org/doc/draft-ietf-httpbis-message-signatures

The sigs package creates and verifies HTTP signatures and Digests.

Image Credit

The banner is Hannibal in the Alps by Richard Barrett Davis (1782–1854). The work is in the public domain.

Pull Requests Welcome

This library is a work in progress, and will benefit from your experience reports, use cases, and contributions. If you have an idea for making this library better, send in a pull request. We're all in this together! 🐘

Documentation

Overview

Package hannibal provides shared helpers and constants for the Hannibal ActivityPub toolkit. Its subpackages implement the inbox router, outbox, HTTP signatures, ActivityStreams document handling, and related machinery.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsActivityPubContentType

func IsActivityPubContentType(contentType string) bool

IsActivityPubContentType returns TRUE if the provided contentType is a valid ActivityPub content type. https://www.w3.org/TR/activitystreams-core/#media-type

func IsActivityPubRequest added in v0.15.1

func IsActivityPubRequest(request *http.Request) bool

IsActivityPubRequest returns TRUE if the request's "Accept" header asks for ActivityPub.

func IsUndoableActivity added in v0.13.1

func IsUndoableActivity(activityType string) bool

IsUndoableActivity returns TRUE if the provided activityType is one that can be undone (as opposed to an activity that must be "Deleted")

func NotActivityPubRequest added in v0.15.1

func NotActivityPubRequest(request *http.Request) bool

NotActivityPubRequest returns TRUE if the request's "Accept" header DOES NOT ask for ActivityPub.

func StripBlindRecipients added in v0.48.0

func StripBlindRecipients(document map[string]any) (map[string]any, error)

StripBlindRecipients returns a deep copy of a document with `bto` and `bcc` removed at every level of nesting. The original is not changed, and the copy keeps the type of every value.

Types

This section is empty.

Directories

Path Synopsis
Package clients provides streams.Client implementations that load ActivityStreams documents from remote servers, with caching and lookup strategies.
Package clients provides streams.Client implementations that load ActivityStreams documents from remote servers, with caching and lookup strategies.
Package collection is an HTTP interface for GET-ing activities from an ActivityPub collection.
Package collection is an HTTP interface for GET-ing activities from an ActivityPub collection.
Package collections provides tools for traversing ActivityStreams collections, represented as streams.Documents, including pagination.
Package collections provides tools for traversing ActivityStreams collections, represented as streams.Documents, including pagination.
Package corpus holds ActivityStreams documents for tests: a set shaped like what fediverse servers publish, and the examples that the W3C publishes with the ActivityStreams specifications.
Package corpus holds ActivityStreams documents for tests: a set shaped like what fediverse servers publish, and the examples that the W3C publishes with the ActivityStreams specifications.
Package datetime formats timestamps for ActivityStreams 2.0 date-time properties, such as "published", "updated", and "startTime".
Package datetime formats timestamps for ActivityStreams 2.0 date-time properties, such as "published", "updated", and "startTime".
Package delivery turns one outbound ActivityPub activity into deliveries to the people it names.
Package delivery turns one outbound ActivityPub activity into deliveries to the people it names.
Package metadata carries server-computed metadata about ActivityStream documents -- knowledge that is ABOUT a document but never part of its wire value.
Package metadata carries server-computed metadata about ActivityStream documents -- knowledge that is ABOUT a document but never part of its wire value.
Package outbox mimics an ActivityPub outbox: it accepts a document, signs it, and delivers it to the recipients addressed by the activity.
Package outbox mimics an ActivityPub outbox: it accepts a document, signs it, and delivers it to the recipients addressed by the activity.
Package property wraps common data values with the conversions used in ActivityStreams.
Package property wraps common data values with the conversions used in ActivityStreams.
Package router provides an ActivityPub inbox handler that parses and validates incoming activities, then routes them by type and object to application logic.
Package router provides an ActivityPub inbox handler that parses and validates incoming activities, then routes them by type and object to application logic.
Package sender provides an object and queue consumer that can send outbound ActivityPub activities from an outbox to actor's inbox URLs.
Package sender provides an object and queue consumer that can send outbound ActivityPub activities from an outbox to actor's inbox URLs.
Package sigs implements the IETF draft specification "Signing HTTP Messages" https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures https://swicg.github.io/activitypub-http-signature/
Package sigs implements the IETF draft specification "Signing HTTP Messages" https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures https://swicg.github.io/activitypub-http-signature/
Package streams implements the ActivityStreams 2.0 specification, providing a simplified view of JSON-LD documents for reading and writing ActivityPub data.
Package streams implements the ActivityStreams 2.0 specification, providing a simplified view of JSON-LD documents for reading and writing ActivityPub data.
Command test-signatures is a manual harness for exercising Hannibal's HTTP signature signing and verification against real-world requests.
Command test-signatures is a manual harness for exercising Hannibal's HTTP signature signing and verification against real-world requests.
Package validator provides pluggable validators that confirm an inbound ActivityPub activity is authentic before the router hands it to application code.
Package validator provides pluggable validators that confirm an inbound ActivityPub activity is authentic before the router hands it to application code.
Package vocab defines the commonly used constants from the ActivityStreams Vocabulary, along with simple validation helpers that confirm a string matches a designated type.
Package vocab defines the commonly used constants from the ActivityStreams Vocabulary, along with simple validation helpers that confirm a string matches a designated type.

Jump to

Keyboard shortcuts

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