Categorygithub.com/go-ap/activitypub
modulepackage
0.0.0-20250212090640-aeb6499ba581
Repository: https://github.com/go-ap/activitypub.git
Documentation: pkg.go.dev

# README

About GoActivityPub: Vocabulary

MIT Licensed Build Status Test Coverage Go Report Card

This project is part of the GoActivityPub library which helps with creating ActivityPub applications using the Go programming language.

It contains data types for most of the Activity Vocabulary and the ActivityPub extension. They are documented accordingly with annotations from these specifications.

You can find an expanded documentation about the whole library on SourceHut.

For discussions about the projects you can write to the discussions mailing list: ~mariusor/[email protected]

For patches and bug reports please use the dev mailing list: ~mariusor/[email protected]

Usage

import vocab "github.com/go-ap/activitypub"

follow := vocab.Activity{
    Type: vocab.FollowType,
    Actor: vocab.IRI("https://example.com/alice"),
    Object: vocab.IRI("https://example.com/janedoe"),
}

Note about generics

The module contains helper functions which make it simpler to deal with the vocab.Item interfaces and they come in two flavours: explicit OnXXX and ToXXX functions corresponding to each type and, a generic pair of functions On[T] and To[T].

import (
    "fmt"

    vocab "github.com/go-ap/activitypub"
)

var it vocab.Item = ... // an ActivityPub object unmarshaled from a request

err := vocab.OnActivity(it, func(act *vocab.Activity) error {
    if vocab.ContentManagementActivityTypes.Contains(act.Type) {
        fmt.Printf("This is a Content Management type activity: %q", act.Type)
    }
    return nil
})

err := vocab.On[vocab.Activity](it, func(act *vocab.Activity) error {
    if vocab.ReactionsActivityTypes.Contains(act.Type) {
        fmt.Printf("This is a Reaction type activity: %q", act.Type)
    }
    return nil
})

Before using the generic versions you should consider that they come with a pretty heavy performance penalty:

goos: linux
goarch: amd64
pkg: github.com/go-ap/activitypub
cpu: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
Benchmark_OnT_vs_On_T/OnObject-8                    752387791       1.633 ns/op
Benchmark_OnT_vs_On_T/On_T_Object-8                   4656264     261.8   ns/op
Benchmark_OnT_vs_On_T/OnActor-8                     739833261       1.596 ns/op
Benchmark_OnT_vs_On_T/On_T_Actor-8                    4035148     301.9   ns/op
Benchmark_OnT_vs_On_T/OnActivity-8                  751173854       1.604 ns/op
Benchmark_OnT_vs_On_T/On_T_Activity-8                 4062598     285.9   ns/op
Benchmark_OnT_vs_On_T/OnIntransitiveActivity-8      675824500       1.640 ns/op
Benchmark_OnT_vs_On_T/On_T_IntransitiveActivity-8     4372798     274.1   ns/op
PASS
ok  	github.com/go-ap/activitypub	11.350s

# Packages

No description provided by the author

# Functions

AcceptNew initializes an Accept activity.
ActivityNew initializes a basic activity.
ActorNew initializes an CanReceiveActivities type actor.
AddNew initializes an Add activity.
AnnounceNew initializes an Announce activity.
ApplicationNew initializes an Application type actor.
ArriveNew initializes an Arrive activity.
BlockNew initializes a Block activity.
CleanRecipients checks if the "it" Item has recipients and cleans them if it does.
CollectionNew initializes a new Collection.
CollectionNew initializes a new CollectionPage.
No description provided by the author
No description provided by the author
No description provided by the author
CopyItemProperties delegates to the correct per type functions for copying properties between matching Activity Objects.
CopyObjectProperties updates the "old" object properties with the "new's" Including ID and Type.
No description provided by the author
No description provided by the author
CreateNew initializes a Create activity.
No description provided by the author
No description provided by the author
DeleteNew initializes a Delete activity.
DerefItem dereferences.
DislikeNew initializes a Dislike activity.
No description provided by the author
FlagNew initializes a Flag activity.
Flatten checks if Item can be flattened to an IRI or array of IRIs and returns it if so.
FlattenActivityProperties flattens the Activity's properties from Object type to IRI.
FlattenActorProperties flattens the Actor's properties from Object types to IRI.
FlattenCollection flattens a Collection's objects to their respective IRIs.
FlattenIntransitiveActivityProperties flattens the Activity's properties from Object type to IRI.
FlattenItemCollection flattens an Item Collection to their respective IRIs.
FlattenObjectProperties flattens the Object's properties from Object types to IRI.
FlattenOrderedCollection flattens an OrderedCollection's objects to their respective IRIs.
FlattenProperties flattens the Item's properties from Object types to IRI.
FlattenToIRI checks if Item can be flatten to an IRI and returns it if so.
FollowNew initializes a Follow activity.
GetAPSource.
No description provided by the author
No description provided by the author
No description provided by the author
GroupNew initializes a Group type actor.
IgnoreNew initializes an Ignore activity.
IntransitiveActivityNew initializes a intransitive activity.
InviteNew initializes an Invite activity.
IRIf formats an IRI from an existing IRI and the CollectionPath type.
IsIRI returns if the current Item interface holds an IRI.
IsIRIs returns if the current Item interface holds an IRI slice.
IsItemCollection returns if the current Item interface holds a Collection.
IsLink returns if the current Item interface holds a Link.
IsNil checks if the object matching an ObjectOrLink interface is nil.
IsObject returns if the current Item interface holds an Object.
ItemCollectionDeduplication normalizes the received arguments lists into a single unified one.
ItemOrderTimestamp is used for ordering a ItemCollection slice using the slice.Sort function It orders i1 and i2 based on their Published and Updated timestamps, whichever is later.
ItemsEqual checks if it and with Items are equal.
JoinNew initializes a Join activity.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
LeaveNew initializes a Leave activity.
LikeNew initializes a Like activity.
LinkNew initializes a new Link.
ListenNew initializes a Listen activity.
MarshalJSON represents just a wrapper for the jsonld.Marshal function.
MentionNew initializes a new Mention.
MoveNew initializes a Move activity.
No description provided by the author
No description provided by the author
NotEmpty tells us if a Item interface value has a non nil value for various types that implement.
ObjectNew initializes a new Object.
OfferNew initializes an Offer activity.
On handles in a generic way the call to fn(*T) if the "it" Item can be asserted to one of the Objects type.
OnActivity calls function fn on it Item if it can be asserted to type *Activity This function should be called if trying to access the Activity specific properties like "object", for the other properties OnObject, or OnIntransitiveActivity should be used instead.
OnActor calls function fn on it Item if it can be asserted to type *Actor This function should be called if trying to access the Actor specific properties like "preferredName", "publicKey", etc.
OnCollection calls function fn on it Item if it can be asserted to type *Collection This function should be called if trying to access the Collection specific properties like "totalItems", "items", etc.
OnCollectionIntf calls function fn on it Item if it can be asserted to a type that implements the CollectionInterface This function should be called if Item represents a collection of ActivityPub objects.
OnCollectionPage calls function fn on it Item if it can be asserted to type *CollectionPage This function should be called if trying to access the CollectionPage specific properties like "partOf", "next", "perv".
OnIntransitiveActivity calls function fn on it Item if it can be asserted to type *IntransitiveActivity This function should be called if trying to access the IntransitiveActivity specific properties like "actor", for the other properties OnObject should be used instead.
OnIRIs calls function fn on it Item if it can be asserted to type IRIs It should be used when Item represents an IRI slice.
OnItem runs function "fn" on the Item "it", with the benefit of destructuring "it" to individual items if it's actually an ItemCollection or an object holding an ItemCollection It is expected that the caller handles the logic of dealing with different Item implementations internally in "fn".
OnItemCollection calls function fn on it Item if it can be asserted to type ItemCollection It should be used when Item represents an Item collection and it's usually used as a way to wrap functionality for other functions that will be called on each item in the collection.
OnLink calls function fn on it Item if it can be asserted to type *Link This function should be safe to use for all types with a structure compatible with the Link type.
OnObject calls function fn on it Item if it can be asserted to type *Object This function should be safe to be called for all types with a structure compatible to the Object type.
OnOrderedCollection calls function fn on it Item if it can be asserted to type *OrderedCollection This function should be called if trying to access the Collection specific properties like "totalItems", "orderedItems", etc.
OnOrderedCollectionPage calls function fn on it Item if it can be asserted to type *OrderedCollectionPage This function should be called if trying to access the OrderedCollectionPage specific properties like "partOf", "next", "perv".
OnPlace calls function fn on it Item if it can be asserted to type *Place This function should be called if trying to access the Place specific properties like "accuracy", "altitude", "latitude", "longitude", "radius", or "units".
OnProfile calls function fn on it Item if it can be asserted to type *Profile This function should be called if trying to access the Profile specific properties like "describes".
OnQuestion calls function fn on it Item if it can be asserted to type Question This function should be called if trying to access the Questions specific properties like "anyOf", "oneOf", "closed", etc.
OnRelationship calls function fn on it Item if it can be asserted to type *Relationship This function should be called if trying to access the Relationship specific properties like "subject", "object", or "relationship".
OnTombstone calls function fn on it Item if it can be asserted to type *Tombstone This function should be called if trying to access the Tombstone specific properties like "formerType" or "deleted".
OrderedCollectionNew initializes a new OrderedCollection.
OrderedCollectionPageNew initializes a new OrderedCollectionPage.
OrganizationNew initializes an Organization type actor.
PersonNew initializes a Person type actor.
No description provided by the author
QuestionNew initializes a Question activity.
ReadNew initializes a Read activity.
RejectNew initializes a Reject activity.
RemoveNew initializes a Remove activity.
ServiceNew initializes a Service type actor.
Split returns the base IRI of received i, if i represents an IRI matching CollectionPath type t.
No description provided by the author
TentativeAcceptNew initializes a TentativeAccept activity.
TentativeRejectNew initializes a TentativeReject activity.
No description provided by the author
ToActivity.
ToActor.
ToCollection.
ToCollectionPage.
ToIntransitiveActivity tries to convert it Item to an IntransitiveActivity object.
ToIRIs.
ToItemCollection returns the item collection contained as part of OrderedCollection, OrderedCollectionPage, Collection and CollectionPage.
ToLink returns a Link pointer to the data in the current Item.
ToObject returns an Object pointer to the data in the current Item It relies on the fact that all the types in this package have a data layout compatible with Object.
ToOrderedCollection.
ToOrderedCollectionPage.
ToPlace.
ToProfile tries to convert the "it" Item to a Profile object.
ToQuestion tries to convert the it Item to a Question object.
ToRelationship tries to convert the "it" Item to a Relationship object.
ToTombstone.
TravelNew initializes a Travel activity.
UndoNew initializes an Undo activity.
UnmarshalJSON tries to detect the type of the object in the json data and then outputs a matching ActivityStreams object, if possible.
UpdateNew initializes an Update activity.
UpdatePersonProperties.
ValidActivityCollection shows if the current ActivityPub end-point type is a valid one for handling Activities.
No description provided by the author
No description provided by the author
ValidActivityCollection shows if the current ActivityPub end-point type is a valid one for handling Objects.
ViewNew initializes a View activity.

# Constants

Activity Types.
ActivityBaseURI the URI for the ActivityStreams namespace.
No description provided by the author
No description provided by the author
Activity Types.
Activity Types.
CanReceiveActivities Types.
Activity Types.
ActivityPub Object Types.
No description provided by the author
Activity Types.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Activity Types.
Activity Types.
Activity Types.
No description provided by the author
EmptyID represents a zero length ID.
EmptyIRI represents a zero length IRI.
No description provided by the author
Activity Types.
Followers https://www.w3.org/TR/activitypub/#followers Every actor SHOULD have a followers collection.
Following https://www.w3.org/TR/activitypub/#following Every actor SHOULD have a following collection.
Activity Types.
CanReceiveActivities Types.
Activity Types.
No description provided by the author
Inbox https://www.w3.org/TR/activitypub/#inbox The inbox is discovered through the inbox property of an actor's profile.
No description provided by the author
Activity Types.
No description provided by the author
Activity Types.
Activity Types.
Liked https://www.w3.org/TR/activitypub/#liked Every actor MAY have a liked collection.
Likes https://www.w3.org/TR/activitypub/#likes Every object MAY have a likes collection.
Activity Types.
No description provided by the author
Activity Types.
MentionType is a link type for @mentions.
Activity Types.
NilID represents by convention an ID which is nil, see details of NilIRI.
NilIRI represents by convention an IRI which is nil Its use is mostly to check if a property of an ActivityPub Item is nil.
NilLangRef represents a convention for a nil language reference.
No description provided by the author
No description provided by the author
Activity Types.
No description provided by the author
No description provided by the author
CanReceiveActivities Types.
Outbox https://www.w3.org/TR/activitypub/#outbox The outbox is discovered through the outbox property of an actor's profile.
No description provided by the author
CanReceiveActivities Types.
No description provided by the author
No description provided by the author
PublicNS is the reference to the Public entity in the ActivityStreams namespace.
Activity Types.
Activity Types.
Activity Types.
No description provided by the author
Activity Types.
activitystreams.
SecurityContextURI the URI for the security namespace (for an Actor's PublicKey).
CanReceiveActivities Types.
Shares https://www.w3.org/TR/activitypub/#shares Every object MAY have a shares collection.
Activity Types.
Activity Types.
No description provided by the author
Activity Types.
Activity Types.
No description provided by the author
Activity Types.
No description provided by the author
Activity Types.

# Variables

No description provided by the author
No description provided by the author
ActorTypes represent the valid Actor types.
CollectionManagementActivityTypes use case primarily deals with activities involving the management of content within collections.
No description provided by the author
ContentExperienceActivityTypes use case primarily deals with describing activities involving listening to, reading, or viewing content.
ContentManagementActivityTypes use case primarily deals with activities that involve the creation, modification or deletion of content.
DefaultLang represents the default language reference used when using the convenience content generation.
EventRSVPActivityTypes use case primarily deals with invitations to events and RSVP type responses.
No description provided by the author
GeoSocialEventsActivityTypes use case primarily deals with activities involving geo-tagging type activities.
GroupManagementActivityTypes use case primarily deals with management of groups.
No description provided by the author
IsNotEmpty checks if an object is empty.
ItemTyperFunc will return an instance of a struct that implements activitypub.Item The default for this package is GetItemByType but can be overwritten.
JSONItemUnmarshal can be set externally to populate a custom object based on its type.
JsonLDContext is a slice of IRIs that form the default context for the objects in the GoActivitypub vocabulary.
LinkTypes represent the valid values for a Link object.
NegatingActivityTypes use case primarily deals with the ability to redact previously completed activities.
NotificationActivityTypes use case primarily deals with calling attention to particular objects or notifications.
No description provided by the author
No description provided by the author
OffersActivityTypes use case deals with activities involving offering one object to another.
No description provided by the author
QuestionActivityTypes use case primarily deals with representing inquiries of any type.
ReactionsActivityTypes use case primarily deals with reactions to content.
RelationshipManagementActivityTypes use case primarily deals with representing activities involving the management of interpersonal and social relationships https://www.w3.org/TR/activitystreams-vocabulary/#motivations-relationships (e.g.
Types contains all valid types in the ActivityPub vocabulary.

# Structs

Activity is a subtype of Object that describes some form of action that may happen, is currently happening, or has already happened.
Actor is generally one of the ActivityStreams actor Types, but they don't have to be.
Collection is a subtype of Activity Pub Object that represents ordered or unordered sets of Activity Pub Object or Link instances.
CollectionPage is a Collection that contains a large number of items and when it becomes impractical for an implementation to serialize every item contained by a Collection using the items property alone.
Endpoints a json object which maps additional (typically server/domain-wide) endpoints which may be useful either for this actor or someone referencing this actor.
IntransitiveActivity Instances of IntransitiveActivity are a subtype of Activity representing intransitive actions.
No description provided by the author
A Link is an indirect, qualified reference to a resource identified by a URL.
Object describes an ActivityPub object of any kind.
OrderedCollection is a subtype of Collection in which members of the logical collection are assumed to always be strictly ordered.
OrderedCollectionPage type extends from both CollectionPage and OrderedCollection.
Place represents a logical or physical location.
Profile a Profile is a content object that describes another Object, typically used to describe CanReceiveActivities Type objects.
PublicKey holds the ActivityPub compatible public key data The document reference can be found at: https://w3c-ccg.github.io/security-vocab/#publicKey.
Question represents a question being asked.
Relationship describes a relationship between two individuals.
Source is intended to convey some sort of source from which the content markup was derived, as a form of provenance, or to support future editing by clients.
Tombstone a Tombstone represents a content object that has been deleted.

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Collections https://www.w3.org/TR/activitypub/#collections [ActivityStreams] defines the collection concept; ActivityPub defines several collections with special behavior.
HasRecipients is an interface implemented by activities to return their audience for further propagation Please take care to the fact that the de-duplication functionality requires a pointer receiver therefore a valid Item interface that wraps around an Object struct, can not be type asserted to HasRecipients.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ValidationErrors is an aggregated error interface that allows a Validator implementation to return all possible errors.
Validator is the interface that needs to be implemented by objects that provide a validation mechanism for incoming ActivityPub Objects or IRIs against an external set of rules.

# Type aliases

No description provided by the author
No description provided by the author
ActivityVocabularyTypes is a type alias for a slice of ActivityVocabularyType elements.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Article
No description provided by the author
No description provided by the author
No description provided by the author
CanReceiveActivities is generally one of the ActivityStreams Actor Types, but they don't have to be.
CollectionPath.
CollectionPaths.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ID designates a unique global identifier.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Item struct.
ItemCollection represents an array of items.
No description provided by the author
JSONUnmarshalerFn is the type of the function that will load the data from a fastjson.Value into an Item that the current package doesn't know about.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Mention is a specialized Link that represents an @mention.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NotEmptyCheckerFn is the type of the function that checks if an object is empty.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
TyperFn is the type of the function which returns an Item struct instance for a specific ActivityVocabularyType.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
WithActivityFn represents a function type that can be used as a parameter for OnActivity helper function.
WithActorFn represents a function type that can be used as a parameter for OnActor helper function.
WithCollectionFn represents a function type that can be used as a parameter for OnCollection helper function.
WithCollectionInterfaceFn represents a function type that can be used as a parameter for OnCollectionIntf helper function.
WithCollectionPageFn represents a function type that can be used as a parameter for OnCollectionPage helper function.
WithIntransitiveActivityFn represents a function type that can be used as a parameter for OnIntransitiveActivity helper function.
WithIRIsFn represents a function type that can be used as a parameter for OnIRIs helper function.
WithItemCollectionFn represents a function type that can be used as a parameter for OnItemCollection helper function.
WithLinkFn represents a function type that can be used as a parameter for OnLink helper function.
WithObjectFn represents a function type that can be used as a parameter for OnObject helper function.
WithOrderedCollectionFn represents a function type that can be used as a parameter for OnOrderedCollection helper function.
WithOrderedCollectionPageFn represents a function type that can be used as a parameter for OnOrderedCollectionPage helper function.
WithQuestionFn represents a function type that can be used as a parameter for OnQuestion helper function.