Documentation
¶
Overview ¶
Package pana can be used to process ActivityStreams messages.
This library is meant to help with implementing fediverse (ActivityPub) clients and servers.
Usage ¶
An application starts with creating a Processor using NewProcessor. This processor should exist for the lifetime of the application, and not a single request.
Incoming messages can then be processed by calling Processor.Unmarshal. This will return an Activity that you can inspect and drill into.
Call Activity.GetType to figure out what type of activity it is. With that information you can then cast the activity to a more specific type which will add new getters and setters for the properties that are set on that activity. You can use Properties to get a set of all properties set on the activity. This lets you handle any property you're interested in.
If an activity has an Object, you can do the same thing. Use Activity.GetObject to get the object. An object may be a reference, or a full object. You can check this with [Object.IsReference]. Once you have a full object, you can use Object.GetType to determine the type and cast it to a more specific type. And you can use Properties to determine the properties set on the object.
Once you've created an Object you wrap it in an Activity and call Processor.Marshal. You can then exchange the resulting JSON using the client-to-server or server-to-server APIs.
If you're going to store ActivityStreams messages, ensure you always store the original you received. Should an implementation bug in Unmarshal result in a problem, you can then always reprocess messages after that's been fixed. But if you store a potentially incorrectly unmarshalled document you may not be able to return to its original form even if you retain the context.
JSON-LD ¶
ActivityStreams uses JSON-LD for its JSON serialisatoin format. Pana doesn't hide this from you, but aims to provide an API that makes working with this simple enough so that you don't have to think about it.
Pana's Unmarshal converts a document to JSON-LD Expanded Document Form. The Marshal method does the opposite, converting to JSON-LD Compacted Document Form.
In JSON-LD all properties, with the exception of 'id' / '@id', are arrays. But if an array only has a single etnry it's typically reduced to its member. This distinction is removed in expanded document form, but it makes the resulting Object a bit verbose to handle.
API ¶
The API Pana exposes is meant to do the right thing for you in 99.9% of cases. Its API is based on what properties are used in practice across the fediverse, and what their values are. This is a more restrictive subset of what the ActivityStreams specification allows for. Pana does this on purpose to guide you towards maximal interoperability with other, potentially JSON-LD unaware, implementations.
For any proprety, you'll either have:
- GetXXX and SetXXX for single-valued properties. These will accept and return strings or encoding/json.RawMessage.
- GetXXX and AddXXX for multi-valued properties. Get will return an iter.Seq, and Add will be variadic. Add appends so can be called multiple times too.
Most value properties return encoding/json.RawMessage. You can look at the JSON-LD context definition to determine what the type of the value should be. This will also be part of the vocabulary documentation for the property you're retrieving. However, remember that this is not enforced, so even if a property is defined as a number it can hold a boolean.
All types in Pana are a code.dny.dev/longdistance.Node. This struct type has exported fields for every JSON-LD keyword, as well as a catch-all Properties field for all other properties. You can directly manipulate any of these, but at that point you're responsible for ensuring you create valid JSON-LD nodes that will compact to a representation non-JSON-LD aware processors will understand. In order to Get, Add or Set properties you need to use the IRI a property maps to. This is part of what the JSON-LD context defines. The code.dny.dev/pana/vocab packages provide the necessary consts.
Index ¶
- func Has[T ld.Internal](in *T, property string) bool
- func IsObjec[T ld.Internal](in *T) bool
- func IsReference[T ld.Internal](in *T) bool
- func Properties[T ld.Internal](in *T) map[string]struct{}
- type Accept
- type Activity
- func (a *Activity) AddActor(ids ...string) *Activity
- func (a *Activity) AddCc(ids ...string) *Activity
- func (a *Activity) AddTo(ids ...string) *Activity
- func (a *Activity) AsAny() *Any
- func (a *Activity) Build() Activity
- func (a *Activity) GetActor() iter.Seq[string]
- func (a *Activity) GetCc() iter.Seq[string]
- func (a *Activity) GetID() string
- func (a *Activity) GetInstrument() *Instrument
- func (a *Activity) GetObject() *Any
- func (a *Activity) GetPublished() json.RawMessage
- func (a *Activity) GetTarget() string
- func (a *Activity) GetTo() iter.Seq[string]
- func (a *Activity) GetType() string
- func (a *Activity) IsIntransitive() bool
- func (a *Activity) SetID(id string) *Activity
- func (a *Activity) SetInstrument(in Instrument) *Activity
- func (a *Activity) SetObject(obj Any) *Activity
- func (a *Activity) SetPublished(v json.RawMessage) *Activity
- func (a *Activity) SetTarget(id string) *Activity
- func (a *Activity) SetType(typ string) *Activity
- type Actor
- func (a *Actor) AddName(ls ...Localised) *Actor
- func (a *Actor) AddSummary(ls ...Localised) *Actor
- func (a *Actor) Build() Any
- func (a *Actor) GetDiscoverable() json.RawMessage
- func (a *Actor) GetEndpoints() *Endpoints
- func (a *Actor) GetFeatured() *Collection
- func (a *Actor) GetFeaturedTags() *Collection
- func (a *Actor) GetFollowers() *Collection
- func (a *Actor) GetFollowing() *Collection
- func (a *Actor) GetIcon() *Image
- func (a *Actor) GetImage() *Image
- func (a *Actor) GetInbox() string
- func (a *Actor) GetIndexable() json.RawMessage
- func (a *Actor) GetLiked() *Collection
- func (a *Actor) GetManuallyApprovesFollowers() json.RawMessage
- func (a *Actor) GetMemorial() json.RawMessage
- func (a *Actor) GetMovedTo() string
- func (a *Actor) GetName() iter.Seq[*Localised]
- func (a *Actor) GetOutbox() string
- func (a *Actor) GetPreferredUsername() json.RawMessage
- func (a *Actor) GetPublicKey() *PublicKey
- func (a *Actor) GetPublished() json.RawMessage
- func (a *Actor) GetSummary() iter.Seq[*Localised]
- func (a *Actor) GetType() string
- func (a *Actor) GetURL() string
- func (a *Actor) SetDiscoverable(v json.RawMessage) *Actor
- func (a *Actor) SetEndpoints(ep Endpoints) *Actor
- func (a *Actor) SetFeatured(c Collection) *Actor
- func (a *Actor) SetFeaturedTags(c Collection) *Actor
- func (a *Actor) SetFollowers(c Collection) *Actor
- func (a *Actor) SetFollowing(c Collection) *Actor
- func (a *Actor) SetIcon(img Image) *Actor
- func (a *Actor) SetImage(img Image) *Actor
- func (a *Actor) SetInbox(url string) *Actor
- func (a *Actor) SetIndexable(v json.RawMessage) *Actor
- func (a *Actor) SetLiked(c Collection) *Actor
- func (a *Actor) SetManuallyApprovesFollowers(v json.RawMessage) *Actor
- func (a *Actor) SetMemorial(v json.RawMessage) *Actor
- func (a *Actor) SetMovedTo(url string) *Actor
- func (a *Actor) SetOutbox(url string) *Actor
- func (a *Actor) SetPreferredUsername(v json.RawMessage) *Actor
- func (a *Actor) SetPublicKey(pk PublicKey) *Actor
- func (a *Actor) SetPublished(v json.RawMessage) *Actor
- func (a *Actor) SetType(typ string) *Actor
- func (a *Actor) SetURL(url string) *Actor
- type Add
- type Announce
- type Any
- type Application
- type Article
- type Audio
- func (a *Audio) AddName(ls ...Localised) *Audio
- func (a *Audio) Build() Audio
- func (a *Audio) GetDuration() json.RawMessage
- func (a *Audio) GetMediaType() json.RawMessage
- func (a *Audio) GetName() iter.Seq[*Localised]
- func (a *Audio) GetType() string
- func (a *Audio) GetURL() string
- func (a *Audio) SetDuration(v json.RawMessage) *Audio
- func (a *Audio) SetMediaType(v json.RawMessage) *Audio
- func (a *Audio) SetType(typ string) *Audio
- func (a *Audio) SetURL(url string) *Audio
- type Block
- type Choice
- type Collection
- func (c *Collection) Build() Collection
- func (c *Collection) GetFirst() *CollectionPage
- func (c *Collection) GetID() string
- func (c *Collection) GetTotalItems() json.RawMessage
- func (c *Collection) GetType() string
- func (c *Collection) SetFirst(p CollectionPage) *Collection
- func (c *Collection) SetID(id string) *Collection
- func (c *Collection) SetTotalItems(v json.RawMessage) *Collection
- func (c *Collection) SetType(typ string) *Collection
- type CollectionPage
- func (p *CollectionPage) Build() CollectionPage
- func (p *CollectionPage) GetNext() string
- func (p *CollectionPage) GetPartOf() string
- func (p *CollectionPage) GetPrev() string
- func (p *CollectionPage) GetType() string
- func (p *CollectionPage) SetNext(url string) *CollectionPage
- func (p *CollectionPage) SetPartOf(url string) *CollectionPage
- func (p *CollectionPage) SetPrev(url string) *CollectionPage
- func (p *CollectionPage) SetType(typ string) *CollectionPage
- type Create
- type Delete
- type Document
- func (d *Document) AddName(ls ...Localised) *Document
- func (d *Document) Build() Document
- func (d *Document) GetBlurhash() json.RawMessage
- func (d *Document) GetDuration() json.RawMessage
- func (d *Document) GetFocalPoint() []json.RawMessage
- func (d *Document) GetHeight() json.RawMessage
- func (d *Document) GetMediaType() json.RawMessage
- func (d *Document) GetName() iter.Seq[*Localised]
- func (d *Document) GetType() string
- func (d *Document) GetURL() string
- func (d *Document) GetWidth() json.RawMessage
- func (d *Document) SetBlurhash(v json.RawMessage) *Document
- func (d *Document) SetDuration(v json.RawMessage) *Document
- func (d *Document) SetFocalPoint(x, y json.RawMessage) *Document
- func (d *Document) SetHeight(v json.RawMessage) *Document
- func (d *Document) SetMediaType(v json.RawMessage) *Document
- func (d *Document) SetType(typ string) *Document
- func (d *Document) SetURL(url string) *Document
- func (d *Document) SetWidth(v json.RawMessage) *Document
- type Emoji
- func (e *Emoji) AddName(ls ...Localised) *Emoji
- func (e *Emoji) Build() Emoji
- func (e *Emoji) GetID() string
- func (e *Emoji) GetIcon() *Icon
- func (e *Emoji) GetName() iter.Seq[*Localised]
- func (e *Emoji) GetType() string
- func (e *Emoji) GetUpdated() json.RawMessage
- func (e *Emoji) SetID(id string) *Emoji
- func (e *Emoji) SetIcon(img Icon) *Emoji
- func (e *Emoji) SetType() *Emoji
- func (e *Emoji) SetUpdated(v json.RawMessage) *Emoji
- type EmojiReact
- type Endpoints
- func (ep *Endpoints) Build() Endpoints
- func (ep *Endpoints) GetOauthAuthzEndpoint() string
- func (ep *Endpoints) GetOauthTokenEndpoint() string
- func (ep *Endpoints) GetProxyURL() string
- func (ep *Endpoints) GetSharedInbox() string
- func (ep *Endpoints) SetOauthAuthzEndpoint(url string) *Endpoints
- func (ep *Endpoints) SetOauthTokenEndpoint(url string) *Endpoints
- func (ep *Endpoints) SetProxyURL(url string) *Endpoints
- func (ep *Endpoints) SetSharedInbox(url string) *Endpoints
- type Event
- type Follow
- type Group
- type Hashtag
- type Icon
- type Image
- type Instrument
- type IntransitiveActivity
- type Like
- type Link
- func (l *Link) AddName(ls ...Localised) *Link
- func (l *Link) Build() Link
- func (l *Link) GetHeight() json.RawMessage
- func (l *Link) GetHref() string
- func (l *Link) GetHreflang() json.RawMessage
- func (l *Link) GetMediaType() json.RawMessage
- func (l *Link) GetName() iter.Seq[*Localised]
- func (l *Link) GetRel() json.RawMessage
- func (l *Link) GetType() string
- func (l *Link) GetWidth() json.RawMessage
- func (l *Link) SetHeight(height json.RawMessage) *Link
- func (l *Link) SetHref(url string) *Link
- func (l *Link) SetHreflang(hreflang json.RawMessage) *Link
- func (l *Link) SetMediaType(mediaType json.RawMessage) *Link
- func (l *Link) SetRel(rel json.RawMessage) *Link
- func (l *Link) SetType(t string) *Link
- func (l *Link) SetWidth(width json.RawMessage) *Link
- type LinkTag
- type Localised
- type Localized
- type Mention
- type Move
- type Note
- func (n *Note) AddActor(ids ...string) *Note
- func (n *Note) AddAttachment(atch ...Any) *Note
- func (n *Note) AddAttributedTo(ids ...string) *Note
- func (n *Note) AddCc(ids ...string) *Note
- func (n *Note) AddContent(ls ...Localised) *Note
- func (n *Note) AddSummary(ls ...Localised) *Note
- func (n *Note) AddTag(tags ...Any) *Note
- func (n *Note) AddTo(ids ...string) *Note
- func (n *Note) Build() Any
- func (n *Note) GetActor() iter.Seq[string]
- func (n *Note) GetAtomURI() string
- func (n *Note) GetAttachment() iter.Seq[*Any]
- func (n *Note) GetAttributedTo() iter.Seq[string]
- func (n *Note) GetCc() iter.Seq[string]
- func (n *Note) GetContent() iter.Seq[*Localised]
- func (n *Note) GetContext() string
- func (n *Note) GetConversation() string
- func (n *Note) GetDirectMessage() json.RawMessage
- func (n *Note) GetID() string
- func (n *Note) GetInReplyTo() string
- func (n *Note) GetInReplyToAtomURI() string
- func (n *Note) GetLikes() *Collection
- func (n *Note) GetPublished() json.RawMessage
- func (n *Note) GetReplies() *Collection
- func (n *Note) GetSensitive() json.RawMessage
- func (n *Note) GetShares() *Collection
- func (n *Note) GetSummary() iter.Seq[*Localised]
- func (n *Note) GetTag() iter.Seq[*Any]
- func (n *Note) GetTo() iter.Seq[string]
- func (n *Note) GetType() string
- func (n *Note) GetURL() string
- func (n *Note) GetUpdated() json.RawMessage
- func (n *Note) SetAtomURI(uri string) *Note
- func (n *Note) SetContext(id string) *Note
- func (n *Note) SetConversation(id string) *Note
- func (n *Note) SetDirectMessage(v json.RawMessage) *Note
- func (n *Note) SetID(id string) *Note
- func (n *Note) SetInReplyTo(id string) *Note
- func (n *Note) SetInReplyToAtomURI(id string) *Note
- func (n *Note) SetLikes(c Collection) *Note
- func (n *Note) SetPublished(v json.RawMessage) *Note
- func (n *Note) SetReplies(c Collection) *Note
- func (n *Note) SetSensitive(v json.RawMessage) *Note
- func (n *Note) SetShares(c Collection) *Note
- func (n *Note) SetType()
- func (n *Note) SetURL(id string) *Note
- func (n *Note) SetUpdated(v json.RawMessage) *Note
- type Object
- func (o *Object) AddAttachment(atch ...Any) *Object
- func (o *Object) AddAttributedTo(ids ...string) *Object
- func (o *Object) AddCc(ids ...string) *Object
- func (o *Object) AddContent(ls ...Localised) *Object
- func (o *Object) AddName(ls ...Localised) *Object
- func (o *Object) AddSummary(ls ...Localised) *Object
- func (o *Object) AddTag(tag ...Any) *Object
- func (o *Object) AddTo(ids ...string) *Object
- func (o *Object) Build() Any
- func (o *Object) GetAtomURI() string
- func (o *Object) GetAttachment() iter.Seq[*Any]
- func (o *Object) GetAttributedTo() iter.Seq[string]
- func (o *Object) GetCc() iter.Seq[string]
- func (o *Object) GetContent() iter.Seq[*Localised]
- func (o *Object) GetContext() string
- func (o *Object) GetConversation() string
- func (o *Object) GetID() string
- func (o *Object) GetInReplyTo() string
- func (o *Object) GetInReplyToAtomURI() string
- func (o *Object) GetLikes() *Collection
- func (o *Object) GetName() iter.Seq[*Localised]
- func (o *Object) GetPublished() json.RawMessage
- func (o *Object) GetReplies() *Collection
- func (o *Object) GetSensitive() json.RawMessage
- func (o *Object) GetShares() *Collection
- func (o *Object) GetSummary() iter.Seq[*Localised]
- func (o *Object) GetTag() iter.Seq[*Any]
- func (o *Object) GetTo() iter.Seq[string]
- func (o *Object) GetType() string
- func (o *Object) GetURL() string
- func (o *Object) GetUpdated() json.RawMessage
- func (o *Object) SetAtomURI(uri string) *Object
- func (o *Object) SetContext(id string) *Object
- func (o *Object) SetConversation(uri string) *Object
- func (o *Object) SetID(id string) *Object
- func (o *Object) SetInReplyTo(url string) *Object
- func (o *Object) SetInReplyToAtomURI(uri string) *Object
- func (o *Object) SetLikes(c Collection) *Object
- func (o *Object) SetPublished(value json.RawMessage) *Object
- func (o *Object) SetReplies(c Collection) *Object
- func (o *Object) SetSensitive(v json.RawMessage) *Object
- func (o *Object) SetShares(c Collection) *Object
- func (o *Object) SetType(t string) *Object
- func (o *Object) SetURL(url string) *Object
- func (o *Object) SetUpdated(v json.RawMessage) *Object
- type Organisation
- type Organization
- type Page
- type Person
- type Place
- type Processor
- func (p *Processor) Marshal(compactionContext json.RawMessage, activity Activity) (json.RawMessage, error)
- func (p *Processor) RegisterContextPath(path string, doc json.RawMessage) error
- func (p *Processor) RegisterContextURL(url string, doc json.RawMessage) error
- func (p *Processor) Unmarshal(document json.RawMessage) (*Activity, error)
- type Profile
- type PublicKey
- func (pk *PublicKey) Build() PublicKey
- func (pk *PublicKey) GetID() string
- func (pk *PublicKey) GetOwner() string
- func (pk *PublicKey) GetPublicKeyPEM() json.RawMessage
- func (pk *PublicKey) SetID(id string) *PublicKey
- func (pk *PublicKey) SetOwner(id string) *PublicKey
- func (pk *PublicKey) SetPublicKeyPEM(v json.RawMessage) *PublicKey
- type Question
- func (q *Question) AddAnyOf(chs ...Choice) *Question
- func (q *Question) AddName(ls ...Localised) *Question
- func (q *Question) AddOneOf(chs ...Choice) *Question
- func (q *Question) Build() Any
- func (q *Question) GetAnyOf() iter.Seq[Choice]
- func (q *Question) GetClosed() json.RawMessage
- func (q *Question) GetEndTime() json.RawMessage
- func (q *Question) GetName() iter.Seq[*Localised]
- func (q *Question) GetOneOf() iter.Seq[Choice]
- func (q *Question) GetSensitive() json.RawMessage
- func (q *Question) GetType() string
- func (q *Question) GetUpdated() json.RawMessage
- func (q *Question) GetVotersCount() json.RawMessage
- func (q *Question) IsMultipleChoice() bool
- func (q *Question) SetClosed(v json.RawMessage) *Question
- func (q *Question) SetEndTime(v json.RawMessage) *Question
- func (q *Question) SetSensitive(v json.RawMessage) *Question
- func (q *Question) SetType()
- func (q *Question) SetUpdated(v json.RawMessage) *Question
- func (q *Question) SetVotersCount(v json.RawMessage) *Question
- type Relationship
- type Remove
- type Service
- type Tombstone
- type Undo
- type Update
- type Video
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Has ¶
Has checks if an object has a specific property set.
It handles JSON-LD keyword aliasses for id and type.
func IsObjec ¶
IsObject indicates if this object is a (partially) complete object.
This means it has an ID, optionally a Type and at least one other property. It doesn't mean the object representation is complete, and you may need to retrieve the object using the ID to get additional properties.
func IsReference ¶
IsReference indicates if this object is a reference.
This means it only has the ID, and optionally a Type, set. You'll need to retrieve the object using the ID to get additional properties.
func Properties ¶
Properties returns a set with an entry for each property set on an object.
It handles JSON-LD keyword aliasses for id and type.
Types ¶
type Accept ¶
type Accept = Activity
Accept is the Accept activity.
func NewAccept ¶
func NewAccept() *Accept
NewAccept initialises a new Accept activity with as.TypeAccept.
type Activity ¶
type Activity Object
Activity is the ActivityStreams Activity type.
This is a more limited view of Object with property getters and setters for the properties that are commonly set on the toplevel activity.
func NewActivity ¶
func NewActivity() *Activity
NewActivity initialises a new activity.
It's initialised with as.TypeCreate. Use Activity.SetType to override it.
func (*Activity) GetActor ¶
GetActor returns the actor IDs from as.Actor.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-actor.
func (*Activity) GetInstrument ¶
func (a *Activity) GetInstrument() *Instrument
GetInstrument returns the instrument in as.Instrument.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-instrument.
func (*Activity) GetObject ¶
GetObject returns the object in as.Object.
This returns as.Any because it can be of many different types. If the Any.GetType doesn't match any known type you can cast it to Object.
https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object.
func (*Activity) GetPublished ¶
func (a *Activity) GetPublished() json.RawMessage
See Object.GetPublished.
func (*Activity) GetTarget ¶
GetTarget returns the ID in as.Target.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-target.
func (*Activity) IsIntransitive ¶
IsIntransitive returns true if the activity has no object.
func (*Activity) SetInstrument ¶
func (a *Activity) SetInstrument(in Instrument) *Activity
SetInstrument sets the instrument in as.Instrument.
func (*Activity) SetObject ¶
SetObject sets the object in as.Object.
It is possible to have more than one object. However, except for JSON-LD aware processors, nobody understands this. If you want to send multiple objects, send multiple activities instead.
func (*Activity) SetPublished ¶
func (a *Activity) SetPublished(v json.RawMessage) *Activity
See Object.SetPublished.
type Actor ¶
type Actor Object
Actor is the ActivityStreams Actor type.
See https://www.w3.org/TR/activitypub/#actor-objects.
func (*Actor) AddSummary ¶
See Object.AddSummary.
func (*Actor) Build ¶
Build finalises the Actor.
This returns Any since that's what Activity.SetObject expects.
func (*Actor) GetDiscoverable ¶
func (a *Actor) GetDiscoverable() json.RawMessage
GetDiscoverable returns the value in mastodon.Discoverable.
When discoverable is absent this returns false. We treat discoverable as opt-in, not opt-out.
func (*Actor) GetEndpoints ¶
GetEndpoints returns the Endpoints from as.Endpoints.
func (*Actor) GetFeatured ¶
func (a *Actor) GetFeatured() *Collection
GetFeatured returns the Collection stored in mastodon.Featured.
func (*Actor) GetFeaturedTags ¶
func (a *Actor) GetFeaturedTags() *Collection
GetFeaturedTags returns the Collection stored in mastodon.FeaturedTags.
func (*Actor) GetFollowers ¶
func (a *Actor) GetFollowers() *Collection
GetFollowers returns the Collection stored in as.Followers.
func (*Actor) GetFollowing ¶
func (a *Actor) GetFollowing() *Collection
GetFollowing returns the Collection stored in as.Following.
func (*Actor) GetIcon ¶
GetIcon returns the Image in as.Icon.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-icon.
func (*Actor) GetImage ¶
GetImage returns the Image in as.Image.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image.
func (*Actor) GetIndexable ¶
func (a *Actor) GetIndexable() json.RawMessage
GetIndexable returns the value in mastodon.Indexable.
When discoverable is absent this returns false. We treat indexable as opt-in, not opt-out.
func (*Actor) GetLiked ¶
func (a *Actor) GetLiked() *Collection
GetLiked returns the Collection stored in as.Liked.
func (*Actor) GetManuallyApprovesFollowers ¶
func (a *Actor) GetManuallyApprovesFollowers() json.RawMessage
GetManuallyApprovesFollowers returns the value in as.ManuallyApprovesFollowers.
See https://swicg.github.io/miscellany/#manuallyApprovesFollowers.
func (*Actor) GetMemorial ¶
func (a *Actor) GetMemorial() json.RawMessage
GetMemorial returns the value in mastodon.Memorial.
It returns false if the property was absent.
func (*Actor) GetMovedTo ¶
GetMovedTo returns the URL from as.MovedTo.
func (*Actor) GetPreferredUsername ¶
func (a *Actor) GetPreferredUsername() json.RawMessage
GetPreferredUsername returns the value in as.PreferredUsername.
func (*Actor) GetPublicKey ¶
GetPublickKey returns the PublicKey stored in secv1.PublicKey.
func (*Actor) GetPublished ¶
func (a *Actor) GetPublished() json.RawMessage
See Object.GetPublished.
func (*Actor) SetDiscoverable ¶
func (a *Actor) SetDiscoverable(v json.RawMessage) *Actor
SetDiscoverable sets the value in mastodon.Discoverable.
func (*Actor) SetEndpoints ¶
SetEndpoints sets the Endpoints in as.Endpoints.
func (*Actor) SetFeatured ¶
func (a *Actor) SetFeatured(c Collection) *Actor
SetFeatured sets the Collection in mastodon.Featured.
func (*Actor) SetFeaturedTags ¶
func (a *Actor) SetFeaturedTags(c Collection) *Actor
SetFeaturedTags sets the Collection in mastodon.FeaturedTags.
func (*Actor) SetFollowers ¶
func (a *Actor) SetFollowers(c Collection) *Actor
SetFollowers sets the Collection in as.Followers.
func (*Actor) SetFollowing ¶
func (a *Actor) SetFollowing(c Collection) *Actor
SetFollowing sets the Collection in as.Following.
func (*Actor) SetIndexable ¶
func (a *Actor) SetIndexable(v json.RawMessage) *Actor
SetIndexable sets the value in mastodon.Indexable.
func (*Actor) SetLiked ¶
func (a *Actor) SetLiked(c Collection) *Actor
SetLiked sets the Collection in as.Liked.
func (*Actor) SetManuallyApprovesFollowers ¶
func (a *Actor) SetManuallyApprovesFollowers(v json.RawMessage) *Actor
SetManuallyApprovesFollowers sets the value in as.ManuallyApprovesFollowers.
func (*Actor) SetMemorial ¶
func (a *Actor) SetMemorial(v json.RawMessage) *Actor
SetMemorial sets the value in mastodon.Memorial.
func (*Actor) SetMovedTo ¶
SetMovedTo sets the URL in as.MovedTo.
func (*Actor) SetPreferredUsername ¶
func (a *Actor) SetPreferredUsername(v json.RawMessage) *Actor
SetPreferredUsername sets the value in as.PreferredUsername.
func (*Actor) SetPublicKey ¶
SetPublicKey sets the PublicKey in secv1.PublicKey.
func (*Actor) SetPublished ¶
func (a *Actor) SetPublished(v json.RawMessage) *Actor
See Object.SetPublished.
type Announce ¶
type Announce = Activity
func NewAnnounce ¶
func NewAnnounce() *Announce
NewAnnounce initialises a new Announce activity with as.TypeAnnounce.
type Any ¶
Any is returned when a property can return Link or Object.
You can use Any.GetType to determine what to cast it to.
type Application ¶
type Application = Actor
type Audio ¶
type Audio Document
Audio is the ActivityStreams Audio type.
It is a Document without width/height but with duration.
func (*Audio) GetDuration ¶
func (a *Audio) GetDuration() json.RawMessage
GetDuration returns the value in as.Duration.
func (*Audio) GetMediaType ¶
func (a *Audio) GetMediaType() json.RawMessage
GetMediaType returns the value in as.MediaType.
func (*Audio) SetDuration ¶
func (a *Audio) SetDuration(v json.RawMessage) *Audio
SetDuration sets the value in as.Duration.
func (*Audio) SetMediaType ¶
func (a *Audio) SetMediaType(v json.RawMessage) *Audio
SetMediaType sets the value in as.MediaType.
type Choice ¶
type Choice Note
Choice represents a choice in a poll. It is a much more limited Note.
func (*Choice) SetReplies ¶
func (c *Choice) SetReplies(cl Collection) *Choice
See Object.SetReplies.
type Collection ¶
type Collection Object
Collection is the ActivityStreams Collection type.
It is also used for the OrderedCollection. Use [Collection.IsOrdered] to see, or Collection.GetType.
func (*Collection) GetFirst ¶
func (c *Collection) GetFirst() *CollectionPage
GetFirst returns the CollectionPage in as.First.
func (*Collection) GetTotalItems ¶
func (c *Collection) GetTotalItems() json.RawMessage
GetTotalItems returns the value from as.TotalItems
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-totalitems.
func (*Collection) SetFirst ¶
func (c *Collection) SetFirst(p CollectionPage) *Collection
SetFirst sets the CollectionPage in as.First.
func (*Collection) SetTotalItems ¶
func (c *Collection) SetTotalItems(v json.RawMessage) *Collection
SetTotalItems sets the value in as.TotalItems.
func (*Collection) SetType ¶
func (c *Collection) SetType(typ string) *Collection
See Object.SetType.
type CollectionPage ¶
type CollectionPage Object
CollectionPage is the ActivityStreams CollectionPage type.
It is also used for the OrderedCollectionPage. Use [CollectionPage.IsOrdered] to see, or CollectionPage.GetType.
func NewCollectionPage ¶
func NewCollectionPage() *CollectionPage
NewCollectionPage initialises a new CollectionPage.
func (*CollectionPage) Build ¶
func (p *CollectionPage) Build() CollectionPage
Build finalises the CollectionPage.
func (*CollectionPage) GetNext ¶
func (p *CollectionPage) GetNext() string
GetNext returns the URL stored in as.Next.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-next.
func (*CollectionPage) GetPartOf ¶
func (p *CollectionPage) GetPartOf() string
GetPartOf returns the URL stored in as.PartOf.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-partof.
func (*CollectionPage) GetPrev ¶
func (p *CollectionPage) GetPrev() string
GetPrev returns the URL stored in as.Prev.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-prev.
func (*CollectionPage) SetNext ¶
func (p *CollectionPage) SetNext(url string) *CollectionPage
SetNext sets the URL in as.Next.
func (*CollectionPage) SetPartOf ¶
func (p *CollectionPage) SetPartOf(url string) *CollectionPage
SetPartOf sets the URL in as.PartOf.
func (*CollectionPage) SetPrev ¶
func (p *CollectionPage) SetPrev(url string) *CollectionPage
SetPrev sets the URL in as.Prev.
func (*CollectionPage) SetType ¶
func (p *CollectionPage) SetType(typ string) *CollectionPage
See Object.SetType.
type Create ¶
type Create = Activity
func NewCreate ¶
func NewCreate() *Create
NewCreate initialises a new Create activity with as.TypeCreate.
type Delete ¶
type Delete = Activity
func NewDelete ¶
func NewDelete() *Delete
NewDelete initialises a new Delete activity with as.TypeDelete.
type Document ¶
type Document Object
Document is the ActivityStreams Document type.
It shares all properties with Link.
func (*Document) AddName ¶
See Object.AddName.
func (*Document) GetBlurhash ¶
func (d *Document) GetBlurhash() json.RawMessage
GetBlurhash returns the value in mastodon.Blurhash.
func (*Document) GetDuration ¶
func (d *Document) GetDuration() json.RawMessage
GetDuration returns the value in as.Duration.
func (*Document) GetFocalPoint ¶
func (d *Document) GetFocalPoint() []json.RawMessage
GetFocalPoint returns the value in mastodon.FocalPoint.
func (*Document) GetHeight ¶
func (d *Document) GetHeight() json.RawMessage
GetHeight returns the value in as.Height.
func (*Document) GetMediaType ¶
func (d *Document) GetMediaType() json.RawMessage
GetMediaType returns the value in as.MediaType.
func (*Document) GetWidth ¶
func (d *Document) GetWidth() json.RawMessage
GetWidth returns the value in as.Width.
func (*Document) SetBlurhash ¶
func (d *Document) SetBlurhash(v json.RawMessage) *Document
SetBlurhash sets the value in mastodon.Blurhash.
func (*Document) SetDuration ¶
func (d *Document) SetDuration(v json.RawMessage) *Document
SetDuration sets the value in as.Duration.
func (*Document) SetFocalPoint ¶
func (d *Document) SetFocalPoint(x, y json.RawMessage) *Document
SetFocalPoint sets the value in mastodon.FocalPoint.
func (*Document) SetHeight ¶
func (d *Document) SetHeight(v json.RawMessage) *Document
SetHeight sets the value in as.Height.
func (*Document) SetMediaType ¶
func (d *Document) SetMediaType(v json.RawMessage) *Document
SetMediaType sets the value in as.MediaType.
type Emoji ¶
type Emoji Object
func (*Emoji) GetID ¶
See Object.GetID.
Beware that Emoji's might not have an ID. This is used for instance-local emoji.
func (*Emoji) GetIcon ¶
GetIcon returns the Image in as.Icon.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-icon.
func (*Emoji) SetUpdated ¶
func (e *Emoji) SetUpdated(v json.RawMessage) *Emoji
See Object.SetUpdated.
type EmojiReact ¶
type EmojiReact = Activity
func NewEmojiReact ¶
func NewEmojiReact() *EmojiReact
NewEmojiReact initialises a new EmojiReact activity with litepub.TypeEmojiReact.
type Endpoints ¶
Endpoints from ActivityPub.
Endpoints does not include support for as.ProvideClientKey or as.SignClientKey because Linked Data Signatures are a menace and should not be used. Use HTTP Signatures instead.
See https://www.w3.org/TR/activitypub/#actor-objects.
func (*Endpoints) GetOauthAuthzEndpoint ¶
GetOauthAuthzEndpoint returns the URL in as.OauthAuthzEndpoint.
func (*Endpoints) GetOauthTokenEndpoint ¶
GetOauthTokenEndpoint returns the URL in as.OauthTokenEndpoint.
func (*Endpoints) GetProxyURL ¶
GetProxyURL returns the URL in as.ProxyURL.
func (*Endpoints) GetSharedInbox ¶
GetSharedInbox returns the URL in as.SharedInbox.
func (*Endpoints) SetOauthAuthzEndpoint ¶
SetOauthAuthzEndpoint sets the URL in as.OauthAuthzEndpoint.
func (*Endpoints) SetOauthTokenEndpoint ¶
SetOauthTokenEndpoint sets the URL in as.OauthTokenEndpoint.
func (*Endpoints) SetProxyURL ¶
SetProxyURL sets the URL in as.ProxyURL.
func (*Endpoints) SetSharedInbox ¶
SetSharedInbox sets the URL in as.SharedInbox.
type Follow ¶
type Follow = Activity
func NewFollow ¶
func NewFollow() *Follow
NewFollow initialises a new Follow activity with as.TypeFollow.
type Icon ¶
type Icon Image
Icon is a more constrained version of Image used with as.Icon.
func (*Icon) GetMediaType ¶
func (i *Icon) GetMediaType() json.RawMessage
GetMediaType returns the value in as.MediaType.
func (*Icon) SetMediaType ¶
func (i *Icon) SetMediaType(v json.RawMessage) *Icon
SetMediaType sets the value in as.MediaType.
type Image ¶
type Image = Document
Image is the ActivityStreams Image type.
It shares all properties with Document.
type Instrument ¶
type Instrument Object
type IntransitiveActivity ¶
type IntransitiveActivity = Object
IntransitiveActivity is the ActivityStreams Intransitive Activity type.
It's aliassed to Object because that's basically what it is. In practice this is rarely if ever used. Polls are modelled as Create Question, even though Question is intransitive.
type Link ¶
Link is the ActivityStreams Link type.
Though Link can have an ID, this never happens in practice because the target of a link is stored in as.Href instead.
func (*Link) GetHeight ¶
func (l *Link) GetHeight() json.RawMessage
GetHeight returns the value from as.Height.
func (*Link) GetHreflang ¶
func (l *Link) GetHreflang() json.RawMessage
GetHreflang returns the value from as.Hreflang.
func (*Link) GetMediaType ¶
func (l *Link) GetMediaType() json.RawMessage
GetMediaType returns the value from as.MediaType.
func (*Link) GetType ¶
See Object.GetType.
This will most commonly be one of:
You'll probably want to use LinkTag for Mention and Hashtag.
func (*Link) GetWidth ¶
func (l *Link) GetWidth() json.RawMessage
GetWidth returns the value from as.Width.
func (*Link) SetHeight ¶
func (l *Link) SetHeight(height json.RawMessage) *Link
SetHeight sets a value in as.Height.
func (*Link) SetHreflang ¶
func (l *Link) SetHreflang(hreflang json.RawMessage) *Link
SetHreflang sets a value in as.Hreflang.
func (*Link) SetMediaType ¶
func (l *Link) SetMediaType(mediaType json.RawMessage) *Link
SetMediaType sets a value in as.MediaType.
type LinkTag ¶
type LinkTag Link
LinkTag is a more constrained version of Link that is used in as.Tag.
It's usually used to represent hashtags and mentions.
func NewLinkTag ¶
func NewLinkTag() *LinkTag
type Localised ¶
Localised represents a value with an optional language tag and direction.
It mirrors a language-mapped attribute in JSON-LD.
func (*Localised) GetLanguage ¶
GetLanguage returns a normalised to lower-case BCP-47 language tag.
The empty string indicates that the language is unknown, not English.
func (*Localised) GetValue ¶
func (l *Localised) GetValue() json.RawMessage
GetValue returns the value.
func (*Localised) SetLanguage ¶
SetLanguage sets the language tag for the value.
This must be a valid BCP-47 language tag and may be normalised to lower-case.
type Note ¶
type Note Object
Note is the ActivityStreams Note type.
func (*Note) AddAttachment ¶
See Object.AddAttachment.
func (*Note) AddAttributedTo ¶
func (*Note) Build ¶
Build finalises the Note.
This returns Any since that's what Activity.SetObject expects.
func (*Note) GetAttachment ¶
See Object.GetAttachment.
func (*Note) GetAttributedTo ¶
func (*Note) GetDirectMessage ¶
func (n *Note) GetDirectMessage() json.RawMessage
GetDirectMessage returns the value in litepub.DirectMessage.
It returns false if the value is absent.
func (*Note) GetInReplyToAtomURI ¶
func (*Note) SetConversation ¶
func (*Note) SetDirectMessage ¶
func (n *Note) SetDirectMessage(v json.RawMessage) *Note
SetDirectMessage sets the value in litepub.DirectMessage.
func (*Note) SetInReplyToAtomURI ¶
func (*Note) SetPublished ¶
func (n *Note) SetPublished(v json.RawMessage) *Note
See Object.SetPublished.
func (*Note) SetSensitive ¶
func (n *Note) SetSensitive(v json.RawMessage) *Note
See Object.SetSensitive.
type Object ¶
Object is the ActivityStreams Object type.
func (*Object) AddAttachment ¶
AddAttachment appends attachments to as.Attachment.
func (*Object) AddAttributedTo ¶
AddAttributedTo appends actor IDs to as.AttributedTo.
func (*Object) AddContent ¶
AddContent adds values to as.Content.
func (*Object) AddSummary ¶
AddSummary adds values to as.Summary.
func (*Object) Build ¶
Build finalises the Object.
This returns Any since that's what Activity.SetObject expects.
func (*Object) GetAtomURI ¶
GetAtomUri returns the URI in ostatus.AtomURI.
func (*Object) GetAttachment ¶
GetAttachment returns the attachments in as.Attachment.
This returns Any because is can be a Document, PropertyValue, a combination of both and more.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment.
func (*Object) GetAttributedTo ¶
GetAttributedTo returns the actor IDs from as.AttributedTo.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attributedto.
func (*Object) GetCc ¶
GetCc returns the audience IDs from as.Cc.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-cc.
func (*Object) GetContent ¶
GetContent returns the localised values in as.Content.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content.
func (*Object) GetContext ¶
GetContext returns the ID in as.Context.
This is not the JSON-LD ld.KeywordContext.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context.
func (*Object) GetConversation ¶
GetConversation returns the URI in ostatus.Conversation.
This is a tag URI.
func (*Object) GetID ¶
GetID returns the object ID from ld.Node.ID.
This is equivalent to the 'id' property in compacted form JSON or the '@id' property in expanded form.
If an object doesn't have an ID but does have other properties it is an anonymous object (a blank node). This represents something that exists but is not named or referencable.
func (*Object) GetInReplyTo ¶
GetInReplyTo returns the URL in as.InReplyTo.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-inreplyto.
func (*Object) GetInReplyToAtomURI ¶
GetInReplyToAtomURI returns the URI in ostatus.InReplyToAtomUri.
func (*Object) GetLikes ¶
func (o *Object) GetLikes() *Collection
GetLikes returns the Collection stored in as.Likes.
func (*Object) GetPublished ¶
func (o *Object) GetPublished() json.RawMessage
GetPublished retrieves the value from as.Published.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-published.
func (*Object) GetReplies ¶
func (o *Object) GetReplies() *Collection
GetReplies returns the Collection stored in as.Replies.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-replies.
func (*Object) GetSensitive ¶
func (o *Object) GetSensitive() json.RawMessage
GetSensitive returns the value from as.Sensitive.
func (*Object) GetShares ¶
func (o *Object) GetShares() *Collection
GetShares returns the Collection stored in as.Shares.
func (*Object) GetSummary ¶
GetSummary returns the localised values in as.Summary.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary.
func (*Object) GetTag ¶
GetTag returns the values in as.Tag.
This returns Any because it can be an Emoji, a Hashtag, combinations of the two or more.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag.
func (*Object) GetTo ¶
GetTo returns the audience IDs from as.To.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-to.
func (*Object) GetType ¶
GetType returns the first type from ld.Node.Type.
This is equivalent to the 'type' property in compacted form JSON or the '@type' property in expanded form.
It will return the empty string if the object has no type.
An object can have multiple types, but this is so uncommon on the fediverse that this method only returns the first type. You can check the size of ld.Node.Type if you'd like.
func (*Object) GetURL ¶
GetURL returns the URL in as.URL.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-url.
func (*Object) GetUpdated ¶
func (o *Object) GetUpdated() json.RawMessage
GetUpdated returns the value in as.Updated.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-endtime.
func (*Object) SetAtomURI ¶
SetAtomUri sets the URI in ostatus.AtomURI.
func (*Object) SetContext ¶
SetContext sets the ID in as.Context.
func (*Object) SetConversation ¶
SetConversation sets the URI in ostatus.Conversation.
func (*Object) SetID ¶
SetID sets the object ID in ld.Node.ID.
func (*Object) SetInReplyTo ¶
SetInReplyTo sets the URL in as.InReplyTo.
func (*Object) SetInReplyToAtomURI ¶
SetInReplyToAtomURI sets the URI in ostatus.InReplyToAtomUri.
func (*Object) SetLikes ¶
func (o *Object) SetLikes(c Collection) *Object
SetLikes sets the Collection in as.Likes.
func (*Object) SetPublished ¶
func (o *Object) SetPublished(value json.RawMessage) *Object
SetPublished sets the value in as.Published.
func (*Object) SetReplies ¶
func (o *Object) SetReplies(c Collection) *Object
SetReplies sets the Collection in as.Replies.
func (*Object) SetSensitive ¶
func (o *Object) SetSensitive(v json.RawMessage) *Object
SetSensitive sets the value in as.Sensitive.
func (*Object) SetShares ¶
func (o *Object) SetShares(c Collection) *Object
SetShares sets the Collection in as.Shares.
func (*Object) SetType ¶
SetType sets the type in ld.Node.Type.
func (*Object) SetUpdated ¶
func (o *Object) SetUpdated(v json.RawMessage) *Object
SetUpdated sets the value in as.Updated.
type Organisation ¶
type Organisation = Actor
type Organization ¶
type Organization = Organisation
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
Processor is used to process incoming messages and prepare outgoing messages.
Your application only needs a single processor instance.
func NewProcessor ¶
NewProcessor initialised a new Processor suitable for dealing with ActivityStreams messages.
It uses loader.Builtin to retrieve contexts and does not retrieve them over the network.
func (*Processor) Marshal ¶
func (p *Processor) Marshal( compactionContext json.RawMessage, activity Activity, ) (json.RawMessage, error)
Marshal takes an Activity and returns JSON-LD in compacted document form.
This is the shape of JSON you want to exchange with other servers and clients.
The compaction context is a JSON document representing the JSON-LD context that should be used for compaction.
Example ¶
package main import ( "encoding/json" "fmt" "log/slog" "code.dny.dev/pana" as "code.dny.dev/pana/vocab/w3/activitystreams" ) func main() { proc := pana.NewProcessor(slog.New(slog.DiscardHandler)) activity := pana.NewActivity(). SetID("https://example.com/id/1"). AddTo(as.PublicCollection). SetObject( pana.NewNote(). AddContent( pana.NewLocalised(). SetValue([]byte(`"We spell color wrong."`)). SetLanguage("en-us"). Build(), ). AddContent( pana.NewLocalised(). SetValue([]byte(`"Omelette du fromage."`)). SetLanguage("fr-FR"). Build(), pana.NewLocalised(). SetValue([]byte(`"Ona li toki."`)). Build(), ). Build()). SetType(as.TypeCreate). Build() compacted, err := proc.Marshal( json.RawMessage(`{"@context":"https://www.w3.org/ns/activitystreams"}`), activity, ) if err != nil { panic(err) } var res any _ = json.Unmarshal(compacted, &res) ind, _ := json.MarshalIndent(res, "", " ") fmt.Println(string(ind)) }
Output: { "@context": "https://www.w3.org/ns/activitystreams", "id": "https://example.com/id/1", "object": { "content": "Ona li toki.", "contentMap": { "en-us": "We spell color wrong.", "fr-FR": "Omelette du fromage." }, "type": "Note" }, "to": "https://www.w3.org/ns/activitystreams#Public", "type": "Create" }
func (*Processor) RegisterContextPath ¶
func (p *Processor) RegisterContextPath( path string, doc json.RawMessage, ) error
RegisterContextPath adds or overrides a context document for the specified remote path in the loader.
Paths are always matches as URL suffixes.
func (*Processor) RegisterContextURL ¶
func (p *Processor) RegisterContextURL( url string, doc json.RawMessage, ) error
RegisterContextURL adds or overrides a context document for the specified remote context URL in the loader.
func (*Processor) Unmarshal ¶
func (p *Processor) Unmarshal( document json.RawMessage, ) (*Activity, error)
Unmarshal takes a JSON document and returns an Activity that represents it using JSON-LD expanded document form.
In JSON-LD the result of expanding a document is always a list. But in the case of ActivityPub we only ever send out a single document at a time, so it returns Activity. If the result happens to have more than one object an error is raised so it doesn't go unnoticed.
Example ¶
package main import ( "fmt" "iter" "log/slog" "maps" "slices" "code.dny.dev/pana" "code.dny.dev/pana/vocab/mastodon" as "code.dny.dev/pana/vocab/w3/activitystreams" ) func main() { // small helper for stable iteration order of properties var listProperties = func(in map[string]struct{}) []string { s := slices.Collect(maps.Keys(in)) slices.Sort(s) return s } var getSingle = func(in iter.Seq[*pana.Localised]) string { for val := range in { return string(val.Value) } return "" } msg := []byte(`{ "@context": [ "https://www.w3.org/ns/activitystreams", { "Emoji": "toot:Emoji", "Hashtag": "as:Hashtag", "atomUri": "ostatus:atomUri", "blurhash": "toot:blurhash", "focalPoint": { "@id": "toot:focalPoint", "@container": "@list" }, "ostatus": "http://ostatus.org#", "toot": "http://joinmastodon.org/ns#", "sensitive": "as:sensitive" } ], "actor": "https://example.com/actor/wcgkaaorsn", "cc": "https://www.w3.org/ns/activitystreams#Public", "id": "https://example.com/id/bikfmutagl", "object": { "atomUri": "https://example.com/atomUri/qbfujvxbeo", "attachment": { "blurhash": "pkbjlvkjjb", "focalPoint": [ 0.7, -0.7 ], "height": 600, "mediaType": "image/jpeg", "name": "banana", "type": "Document", "url": "https://example.com/url/odybnszymk", "width": 800 }, "attributedTo": "https://example.com/attributedTo/ytoxvxmalh", "content": "eating a banana", "id": "https://example.com/id/bfcqgpkwjv", "published": "2020-10-01T16:00:00Z", "replies": { "first": { "id": "https://example.com/id/htpqbwrroa", "next": "https://example.com/next/dsqoqssppw", "partOf": "https://example.com/partOf/bjkaungqre", "type": "CollectionPage" }, "id": "https://example.com/id/edjlqpbspm", "type": "Collection" }, "sensitive": true, "summary": "food, eye contact", "tag": [ { "icon": { "mediaType": "image/jpeg", "type": "Image", "url": "https://example.com/url/kkurwzofjc" }, "id": "https://example.com/id/xadgmrnzdk", "name": "bananadance", "type": "Emoji", "updated": "2020-10-01T16:00:00Z" }, { "href": "https://example.com/href/qzqgetcjfv", "name": "#food", "type": "Hashtag" } ], "to": "https://www.w3.org/ns/activitystreams#Public", "type": "Note", "url": "https://example.com/url/lpsbcbqdnm" }, "published": "2020-10-01T16:00:00Z", "to": "https://www.w3.org/ns/activitystreams#Public", "type": "Create" }`) proc := pana.NewProcessor(slog.New(slog.DiscardHandler)) activity, err := proc.Unmarshal(msg) if err != nil { panic(err) } fmt.Println("#----- Activity -----#") // what type of Activity did we just get? fmt.Println("type:", activity.GetType()) // what properties are set on the Activity? for _, property := range listProperties(pana.Properties(activity)) { fmt.Println("property:", property) } fmt.Println("\n#----- Object -----#") // what's our object? obj := activity.GetObject() // do we have a real object or a reference? fmt.Println("object is a reference:", pana.IsReference(obj)) // what's the object type? fmt.Println("object type:", obj.GetType()) // what are the properties on the object? for _, property := range listProperties(pana.Properties(obj)) { fmt.Println("property:", property) } // time to convert it note := (*pana.Note)(obj) // Note is a more limited pana.Object with only the getters and setters for microblog posts. fmt.Println("\n#----- Object attachments -----#") for atch := range note.GetAttachment() { switch atch.GetType() { case as.TypeDocument: doc := (*pana.Document)(atch) fmt.Println("height:", string(doc.GetHeight())) fmt.Println("width:", string(doc.GetWidth())) fmt.Println("URL:", doc.GetURL()) default: panic("unknown attachment type") } } fmt.Println("\n#----- Object tags -----#") // lets get all the tags for tag := range note.GetTag() { switch tag.GetType() { case as.TypeHashtag: ht := (*pana.Hashtag)(tag) fmt.Println("hashtag name:", getSingle(ht.GetName())) fmt.Println("hashtag IRI:", ht.GetHref()) case mastodon.TypeEmoji: emo := (*pana.Emoji)(tag) fmt.Println("emoji name:", getSingle(emo.GetName())) fmt.Println("emoj URL:", emo.GetIcon().GetURL()) default: panic("unsupported tag type") } } }
Output: #----- Activity -----# type: https://www.w3.org/ns/activitystreams#Create property: https://www.w3.org/ns/activitystreams#actor property: https://www.w3.org/ns/activitystreams#cc property: https://www.w3.org/ns/activitystreams#object property: https://www.w3.org/ns/activitystreams#published property: https://www.w3.org/ns/activitystreams#to property: id property: type #----- Object -----# object is a reference: false object type: https://www.w3.org/ns/activitystreams#Note property: http://ostatus.org#atomUri property: https://www.w3.org/ns/activitystreams#attachment property: https://www.w3.org/ns/activitystreams#attributedTo property: https://www.w3.org/ns/activitystreams#content property: https://www.w3.org/ns/activitystreams#published property: https://www.w3.org/ns/activitystreams#replies property: https://www.w3.org/ns/activitystreams#sensitive property: https://www.w3.org/ns/activitystreams#summary property: https://www.w3.org/ns/activitystreams#tag property: https://www.w3.org/ns/activitystreams#to property: https://www.w3.org/ns/activitystreams#url property: id property: type #----- Object attachments -----# height: 600 width: 800 URL: https://example.com/url/odybnszymk #----- Object tags -----# emoji name: "bananadance" emoj URL: https://example.com/url/kkurwzofjc hashtag name: "#food" hashtag IRI: https://example.com/href/qzqgetcjfv
type PublicKey ¶
PublicKey is the W3ID Security v1 Public Key.
func (*PublicKey) GetOwner ¶
GetOwner returns the ID in secv1.Owner.
func (*PublicKey) GetPublicKeyPEM ¶
func (pk *PublicKey) GetPublicKeyPEM() json.RawMessage
GetPublicKeyPEM returns the value in secv1.PublicKeyPem.
func (*PublicKey) SetOwner ¶
SetOwner sets the ID in secv1.Owner.
func (*PublicKey) SetPublicKeyPEM ¶
func (pk *PublicKey) SetPublicKeyPEM(v json.RawMessage) *PublicKey
SetPublicKeyPEM sets the value in secv1.PublicKeyPem.
type Question ¶
type Question IntransitiveActivity
Question is the ActivityStreams Question object.
func (*Question) AddName ¶
See Object.AddName.
func (*Question) Build ¶
Build finalises the Question.
This returns Any since that's what Activity.SetObject expects.
func (*Question) GetAnyOf ¶
GetAnyOf gets the Choice in as.AnyOf.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-oneof.
func (*Question) GetClosed ¶
func (q *Question) GetClosed() json.RawMessage
GetClosed returns the value in as.Closed.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-closed.
func (*Question) GetEndTime ¶
func (q *Question) GetEndTime() json.RawMessage
GetEndTime returns the value in as.EndTime.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-endtime.
func (*Question) GetOneOf ¶
GetOneOf gets the Choice in as.OneOf.
See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-oneof.
func (*Question) GetSensitive ¶
func (q *Question) GetSensitive() json.RawMessage
See Object.GetSensitive.
func (*Question) GetUpdated ¶
func (q *Question) GetUpdated() json.RawMessage
See Object.GetUpdated.
func (*Question) GetVotersCount ¶
func (q *Question) GetVotersCount() json.RawMessage
GetVotersCount returns the value in mastodon.VotersCount.
func (*Question) IsMultipleChoice ¶
IsMultipleChoice checks if this is a multiple-choice question.
func (*Question) SetClosed ¶
func (q *Question) SetClosed(v json.RawMessage) *Question
SetClosed sets the value in as.Closed.
func (*Question) SetEndTime ¶
func (q *Question) SetEndTime(v json.RawMessage) *Question
SetEndTime sets the value in as.EndTime.
func (*Question) SetSensitive ¶
func (q *Question) SetSensitive(v json.RawMessage) *Question
See Object.SetSensitive.
func (*Question) SetUpdated ¶
func (q *Question) SetUpdated(v json.RawMessage) *Question
See Object.SetUpdated.
func (*Question) SetVotersCount ¶
func (q *Question) SetVotersCount(v json.RawMessage) *Question
SetVotersCount sets the value in mastodon.VotersCount.
type Relationship ¶
type Relationship Object
Relationship is the ActivityStreams Relationship type.
func NewRelationship ¶
func NewRelationship() *Relationship
NewRelationship initialises a new Relationship.
func (*Relationship) Build ¶
func (r *Relationship) Build() Relationship
Build finalises the Relationship.
type Remove ¶
type Remove = Activity
func NewRemove ¶
func NewRemove() *Remove
NewRemove initialises a new Remove activity with as.TypeRemove.
Source Files
¶
- activity.go
- actor.go
- any.go
- article.go
- audio.go
- collection.go
- doc.go
- document.go
- emoji.go
- endpoint.go
- event.go
- hashtag.go
- helpers.go
- icon.go
- image.go
- instrument.go
- link.go
- localised.go
- mention.go
- note.go
- object.go
- page.go
- pana.go
- place.go
- processor.go
- profile.go
- public_key.go
- question.go
- relationship.go
- tombstone.go
- video.go
Directories
¶
Path | Synopsis |
---|---|
internal
|
|
Package vocab provides context documents and Go consts for all the terms defined in each context.
|
Package vocab provides context documents and Go consts for all the terms defined in each context. |
dublincore
Package dublincore contains packages for JSON-LD contexts under purl.org/dc.
|
Package dublincore contains packages for JSON-LD contexts under purl.org/dc. |
dublincore/terms
Package terms contains terms for the Dublin Core Terms namespace.
|
Package terms contains terms for the Dublin Core Terms namespace. |
fedibird
Package fedibird contains terms for the Fedibird namespace.
|
Package fedibird contains terms for the Fedibird namespace. |
gotosocial
Package gotosocial contains terms for the GoToSocial namespace.
|
Package gotosocial contains terms for the GoToSocial namespace. |
litepub
Package litepub contains terms for the Litepub namespace.
|
Package litepub contains terms for the Litepub namespace. |
mastodon
Package mastodon contains terms for the toot namespace.
|
Package mastodon contains terms for the toot namespace. |
misskey
Package misskey contains terms for the Misskey namespace.
|
Package misskey contains terms for the Misskey namespace. |
ostatus
Package ostatus contains terms for the Ostatus.org namespace.
|
Package ostatus contains terms for the Ostatus.org namespace. |
schema
Package schema contains terms for the Schema.org namespace.
|
Package schema contains terms for the Schema.org namespace. |
w3
Package w3 contains packages for JSON-LD contexts under w3.org/.
|
Package w3 contains packages for JSON-LD contexts under w3.org/. |
w3/activitystreams
Package activitystreams contains terms for the ActivityStreams namespace.
|
Package activitystreams contains terms for the ActivityStreams namespace. |
w3/ldp
Package ldp contains terms for the Linked Data Platform namespace.
|
Package ldp contains terms for the Linked Data Platform namespace. |
w3/rdf/schema
Package schema contains terms for the RDF Schema namespace.
|
Package schema contains terms for the RDF Schema namespace. |
w3id
Package w3id contains packages for JSON-LD contexts under w3id.org/.
|
Package w3id contains packages for JSON-LD contexts under w3id.org/. |
w3id/credentialsv1
Package credv1 contains terms for the W3ID Credentials namespace.
|
Package credv1 contains terms for the W3ID Credentials namespace. |
w3id/identityv1
Package identityv1 contains terms for the W3ID Identity namespace.
|
Package identityv1 contains terms for the W3ID Identity namespace. |
w3id/payswarmv1
Package payswarmv1 contains terms for the W3ID Payswarm namespace.
|
Package payswarmv1 contains terms for the W3ID Payswarm namespace. |
w3id/permissionsv1
Package permsv1 contains terms for the W3ID Permissions namespace.
|
Package permsv1 contains terms for the W3ID Permissions namespace. |
w3id/securityv1
Package secv1 contains terms for the W3ID Security namespace.
|
Package secv1 contains terms for the W3ID Security namespace. |