Documentation
ΒΆ
Overview ΒΆ
Package astreams implements JSON serialization/deserialization support for the ActivityStreams 2.0 vocabulary. Simply use json.Marshal/json.Unmarshal on AS 2.0 compliant objects to obtain their JSON/Go representation respectively.
Indirect object references such as a link to an outbox collection within an actor profile need to be fetched explicitly and parsed as a separate object.
Index ΒΆ
- func ConcreteType(t ObjectLinker) (reflectType, astreamsType string)
- func DecodeJSON[T ActivityStreamer](jsonPayload io.Reader) (T, error)
- func EncodeJSON[T ActivityStreamer](toEncode T) ([]byte, error)
- type Accept
- type Activity
- type ActivityStreamer
- type Actor
- type Add
- type Announce
- type Application
- type Arrive
- type Article
- type Audio
- type Block
- type Collection
- type CollectionPage
- type Create
- type Delete
- type Dislike
- type Document
- type Endpoints
- type Event
- type Flag
- type Follow
- type Group
- type Hashtag
- type Icon
- type Icons
- type Ignore
- type Image
- type IntransitiveActivity
- type Invite
- type Join
- type JsonPayload
- type Leave
- type Like
- type Link
- type Listen
- type Location
- type Mention
- type Move
- type Note
- type Object
- type ObjectLinker
- type ObjectOrLink
- type ObjectOrLinkOrString
- type Offer
- type OrderedCollection
- type OrderedCollectionPage
- type Organization
- type Page
- type Person
- type Place
- type Profile
- type PropertyValue
- type PublicKey
- type Question
- type Read
- type Reject
- type Relationship
- type Remove
- type Service
- type StringWithCollection
- type StringWithCollectionPage
- type StringWithOrderedCollection
- type StringWithOrderedCollectionPage
- type TentativeAccept
- type TentativeReject
- type Tombstone
- type Travel
- type Undo
- type Update
- type Video
- type View
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func ConcreteType ΒΆ
func ConcreteType(t ObjectLinker) (reflectType, astreamsType string)
ConcreteType returns both, the type name obtained using reflection, and the Type property of the Object / Link JSON payload. The object's own Type property is going to be more specific, so use that where useful.
func DecodeJSON ΒΆ added in v0.6.0
func DecodeJSON[T ActivityStreamer](jsonPayload io.Reader) (T, error)
DecodeJSON is the generic unmarshaller for any valid ActivityStreams 2.0 object
func EncodeJSON ΒΆ added in v0.6.0
func EncodeJSON[T ActivityStreamer](toEncode T) ([]byte, error)
EncodeJSON is the generic marshaller for any valid ActivityStreams 2.0 object
Types ΒΆ
type Activity ΒΆ
type Activity struct {
Object
Actor *ObjectOrLinkOrString `json:"actor,omitempty"`
ActivityObject *ObjectOrLinkOrString `json:"object,omitempty"` // the 'object' property of Activity
Instrument *ObjectOrLinkOrString `json:"instrument,omitempty"`
Origin *ObjectOrLinkOrString `json:"origin,omitempty"`
Result *ObjectOrLinkOrString `json:"result,omitempty"`
Target *ObjectOrLinkOrString `json:"target,omitempty"`
}
type ActivityStreamer ΒΆ added in v0.5.0
type ActivityStreamer interface {
Object | Link | Actor | Activity | IntransitiveActivity | Collection | CollectionPage |
OrderedCollection | OrderedCollectionPage | Location | Icon | Image | Place | Profile |
Tombstone | Relationship | Question
}
ActivityStreamer is a generic type constraint representing all valid Activity Streams 2.0 types
type Actor ΒΆ
type Actor struct {
Object
Devices *StringWithCollection `json:"devices,omitempty"`
Discoverable *bool `json:"discoverable,omitempty"`
Endpoints *Endpoints `json:"endpoints,omitempty"`
Featured *StringWithOrderedCollection `json:"featured,omitempty"`
FeaturedTags *StringWithCollection `json:"featuredTags,omitempty"`
Followers *StringWithOrderedCollection `json:"followers,omitempty"`
Following *StringWithOrderedCollection `json:"following,omitempty"`
Inbox *StringWithOrderedCollection `json:"inbox,omitempty"`
Indexable *bool `json:"indexable,omitempty"`
Liked *StringWithOrderedCollection `json:"liked,omitempty"`
ManuallyApprovesFollowers *bool `json:"manuallyApprovesFollowers,omitempty"`
Memorial *bool `json:"memorial,omitempty"`
Outbox *StringWithOrderedCollection `json:"outbox,omitempty"`
PreferredUsername string `json:"preferredUsername,omitempty"`
PublicKey *PublicKey `json:"publicKey,omitempty"`
Streams *ObjectOrLinkOrString `json:"streams,omitempty"`
}
type Arrive ΒΆ
type Arrive = IntransitiveActivity
type Collection ΒΆ
type Collection struct {
Object
Current *StringWithCollectionPage `json:"current,omitempty"`
First *StringWithCollectionPage `json:"first,omitempty"`
Items *ObjectOrLinkOrString `json:"items,omitempty"`
Last *StringWithCollectionPage `json:"last,omitempty"`
TotalItems int `json:"totalItems,omitempty"`
}
func (*Collection) MarshalJSON ΒΆ added in v0.7.0
func (col *Collection) MarshalJSON() ([]byte, error)
type CollectionPage ΒΆ
type CollectionPage struct {
Collection
Next *ObjectOrLinkOrString `json:"next,omitempty"`
PartOf *ObjectOrLinkOrString `json:"partOf,omitempty"`
Prev *ObjectOrLinkOrString `json:"prev,omitempty"`
}
func (*CollectionPage) MarshalJSON ΒΆ added in v0.7.0
func (colp *CollectionPage) MarshalJSON() ([]byte, error)
type Endpoints ΒΆ
type Endpoints struct {
OauthAuthorizationEndpoint string `json:"oauthAuthorizationEndpoint,omitempty"`
OauthTokenEndpoint string `json:"oauthTokenEndpoint,omitempty"`
ProvideClientKey string `json:"provideClientKey,omitempty"`
ProxyUrl string `json:"proxyUrl,omitempty"`
SignClientKey string `json:"signClientKey,omitempty"`
}
type Icons ΒΆ
Icons is a type representing the possible ActivityPub icon values
func (*Icons) MarshalJSON ΒΆ
func (*Icons) String ΒΆ
Implements https://golang.org/pkg/fmt/#Stringer
func (*Icons) UnmarshalJSON ΒΆ
Implements https://golang.org/pkg/encoding/json/#Unmarshaler
type IntransitiveActivity ΒΆ
type IntransitiveActivity struct {
Object
Actor *ObjectOrLinkOrString `json:"actor,omitempty"`
Instrument *ObjectOrLinkOrString `json:"instrument,omitempty"`
Origin *ObjectOrLinkOrString `json:"origin,omitempty"`
Result *ObjectOrLinkOrString `json:"result,omitempty"`
Target *ObjectOrLinkOrString `json:"target,omitempty"`
}
type JsonPayload ΒΆ added in v0.6.0
type JsonPayload struct {
Type string `json:"type"`
}
func DecodePayloadObjectType ΒΆ added in v0.6.0
func DecodePayloadObjectType(payload io.Reader) (JsonPayload, error)
DecodePayloadObjectType can be used to check the specific type of unknown JSON payload
payloadMeta, err := DecodePayloadObjectType(payload)
if err != nil {
//
}
switch payloadMeta.Type {
case "Note":
var note Note
err = json.Unmarshal([]byte(tc), ¬e)
if err != nil {
//
}
case "Offer":
var offer Offer
err = json.Unmarshal([]byte(tc), &offer)
if err != nil {
//
}
case "Person":
var person Person
err = json.Unmarshal([]byte(tc), &person)
if err != nil {
//
}
if person.Name == "" {
//
}
default:
var obj ObjectOrLinkOrString
err = json.Unmarshal([]byte(tc), &obj)
if err != nil {
//
}
}
type Link ΒΆ
type Link struct {
ASContext any `json:"@context,omitempty"`
ASLanguage string `json:"@language,omitempty"`
Height int `json:"height,omitempty"`
Href string `json:"href,omitempty"`
Hreflang string `json:"hreflang,omitempty"`
MediaType string `json:"mediaType,omitempty"`
Name string `json:"name,omitempty"`
NameMap map[string]string `json:"nameMap,omitempty"`
Preview *ObjectOrLinkOrString `json:"preview,omitempty"`
Published *time.Time `json:"published,omitempty"`
Rel []string `json:"rel,omitempty"`
Type string `json:"type"`
Value string `json:"value,omitempty"`
Width int `json:"width,omitempty"`
}
Link represents the base ActivityStreams Link and all of its properties Other Link types extend it
type Location ΒΆ
type Location struct {
Object
Altitude int `json:"altitude,omitempty"`
Latitude float32 `json:"latitude,omitempty"`
Longitude float32 `json:"longitude,omitempty"`
Units string `json:"units,omitempty"`
}
func (*Location) String ΒΆ
Implements https://golang.org/pkg/fmt/#Stringer
type Object ΒΆ
type Object struct {
AlsoKnownAs *ObjectOrLinkOrString `json:"alsoKnownAs,omitempty"`
ASContext any `json:"@context,omitempty"`
ASLanguage string `json:"@language,omitempty"`
AtID string `json:"@id,omitempty"`
AtType string `json:"@type,omitempty"`
Attachment *ObjectOrLinkOrString `json:"attachment,omitempty"`
AttributedTo *ObjectOrLinkOrString `json:"attributedTo,omitempty"`
Audience *ObjectOrLinkOrString `json:"audience,omitempty"`
Bcc *ObjectOrLinkOrString `json:"bcc,omitempty"`
Bto *ObjectOrLinkOrString `json:"bto,omitempty"`
Cc *ObjectOrLinkOrString `json:"cc,omitempty"`
Content string `json:"content,omitempty"` // needs to be parsed safely ie by https://golang.org/pkg/html/template
ContentMap map[string]string `json:"contentMap,omitempty"`
Context *ObjectOrLinkOrString `json:"context,omitempty"`
Conversation string `json:"conversation,omitempty"`
Duration string `json:"duration,omitempty"` // xsd:duration
EndTime *time.Time `json:"endTime,omitempty"`
Generator *ObjectOrLinkOrString `json:"generator,omitempty"`
Icon *ObjectOrLinkOrString `json:"icon,omitempty"`
ID string `json:"id,omitempty"`
Image *ObjectOrLinkOrString `json:"image,omitempty"`
InReplyTo *ObjectOrLinkOrString `json:"inReplyTo,omitempty"`
Likes *ObjectOrLinkOrString `json:"likes,omitempty"`
Location *ObjectOrLinkOrString `json:"location,omitempty"`
MediaType string `json:"mediaType,omitempty"`
MovedTo *ObjectOrLinkOrString `json:"movedTo,omitempty"`
Name string `json:"name,omitempty"`
NameMap map[string]string `json:"nameMap,omitempty"`
Preview *ObjectOrLinkOrString `json:"preview,omitempty"`
Published *time.Time `json:"published,omitempty"`
Replies *OrderedCollection `json:"replies,omitempty"`
Schema string `json:"schema,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
Source *ObjectOrLinkOrString `json:"source,omitempty"`
StartTime *time.Time `json:"startTime,omitempty"`
Summary string `json:"summary,omitempty"`
SummaryMap map[string]string `json:"summaryMap,omitempty"`
Tag *ObjectOrLinkOrString `json:"tag,omitempty"`
To *ObjectOrLinkOrString `json:"to,omitempty"`
Type string `json:"type"`
Updated *time.Time `json:"updated,omitempty"`
URL *ObjectOrLinkOrString `json:"url,omitempty"`
}
Object represents the base ActivityStreams Object and all of its properties Most of the other types extend Object
type ObjectLinker ΒΆ added in v0.6.0
ObjectLinker can be either a (sub)type of 'Object' or a (sub)type of 'Link'
type ObjectOrLink ΒΆ
type ObjectOrLink []ObjectLinker
ObjectOrLink is a wrapper type that represents any valid ActivityStreams 2.0 object or link Single objects are still presented as slices, but with a single element
func (*ObjectOrLink) MarshalJSON ΒΆ
func (ol *ObjectOrLink) MarshalJSON() ([]byte, error)
func (*ObjectOrLink) UnmarshalJSON ΒΆ
func (ol *ObjectOrLink) UnmarshalJSON(data []byte) error
Implements https://golang.org/pkg/encoding/json/#Unmarshaler
type ObjectOrLinkOrString ΒΆ
type ObjectOrLinkOrString struct {
Target ObjectOrLink
URL []string
}
ObjectOrLinkOrString is a type that can either represent simple string URL(s) or an Object/Link slice
func (*ObjectOrLinkOrString) MarshalJSON ΒΆ
func (ols *ObjectOrLinkOrString) MarshalJSON() ([]byte, error)
func (*ObjectOrLinkOrString) String ΒΆ
func (ols *ObjectOrLinkOrString) String() string
Implements https://golang.org/pkg/fmt/#Stringer
func (*ObjectOrLinkOrString) UnmarshalJSON ΒΆ
func (ols *ObjectOrLinkOrString) UnmarshalJSON(data []byte) error
Implements https://golang.org/pkg/encoding/json/#Unmarshaler
type OrderedCollection ΒΆ
type OrderedCollection struct {
Object
Current *StringWithOrderedCollectionPage `json:"current,omitempty"`
First *StringWithOrderedCollectionPage `json:"first,omitempty"`
Last *StringWithOrderedCollectionPage `json:"last,omitempty"`
OrderedItems *ObjectOrLinkOrString `json:"orderedItems"`
TotalItems int `json:"totalItems"`
}
OrderedCollection implements https://golang.org/pkg/sort/#Interface
func (OrderedCollection) Len ΒΆ
func (oc OrderedCollection) Len() int
func (OrderedCollection) Less ΒΆ
func (oc OrderedCollection) Less(i, j int) bool
func (*OrderedCollection) MarshalJSON ΒΆ added in v0.7.0
func (oc *OrderedCollection) MarshalJSON() ([]byte, error)
func (OrderedCollection) SortByUpdated ΒΆ
func (oc OrderedCollection) SortByUpdated()
SortByUpdated sorts OrderedCollection objects by Updated rather than Published date
func (*OrderedCollection) String ΒΆ
func (oc *OrderedCollection) String() string
Implements https://golang.org/pkg/fmt/#Stringer
func (OrderedCollection) Swap ΒΆ
func (oc OrderedCollection) Swap(i, j int)
type OrderedCollectionPage ΒΆ
type OrderedCollectionPage struct {
OrderedCollection
Next *ObjectOrLinkOrString `json:"next,omitempty"`
PartOf *ObjectOrLinkOrString `json:"partOf,omitempty"`
Prev *ObjectOrLinkOrString `json:"prev,omitempty"`
StartIndex uint `json:"startIndex,omitempty"`
}
OrderedCollectionPage implements https://golang.org/pkg/sort/#Interface
func (*OrderedCollectionPage) MarshalJSON ΒΆ added in v0.7.0
func (ocolp *OrderedCollectionPage) MarshalJSON() ([]byte, error)
type Organization ΒΆ
type Organization = Actor
type Profile ΒΆ
type Profile struct {
Object
Describes ObjectOrLinkOrString `json:"describes,omitempty"`
}
type PropertyValue ΒΆ
type PropertyValue = Link
type Question ΒΆ
type Question struct {
IntransitiveActivity
// only OneOf or AnyOf can be set, not both
AnyOf *ObjectOrLinkOrString `json:"anyOf,omitempty"`
Closed *time.Time `json:"closed,omitempty"`
OneOf *ObjectOrLinkOrString `json:"oneOf,omitempty"`
}
type Relationship ΒΆ
type Relationship struct {
Object
Relationship string `json:"relationship,omitempty"`
RelationshipObject *ObjectOrLinkOrString `json:"object,omitempty"`
Subject *ObjectOrLinkOrString `json:"subject,omitempty"`
}
type StringWithCollection ΒΆ
type StringWithCollection struct {
Collection Collection
URL string
}
StringWithCollection can store a string URL pointing to a Collection, which can itself be stored in the struct
func (*StringWithCollection) MarshalJSON ΒΆ
func (sc *StringWithCollection) MarshalJSON() ([]byte, error)
func (*StringWithCollection) String ΒΆ
func (sc *StringWithCollection) String() string
Implements https://golang.org/pkg/fmt/#Stringer
func (*StringWithCollection) UnmarshalJSON ΒΆ
func (sc *StringWithCollection) UnmarshalJSON(data []byte) error
Implements https://golang.org/pkg/encoding/json/#Unmarshaler
type StringWithCollectionPage ΒΆ added in v0.8.0
type StringWithCollectionPage struct {
CollectionPage CollectionPage
URL string
}
StringWithCollectionPage can store a string URL pointing to a CollectionPage, which can itself be stored in the struct
func (*StringWithCollectionPage) MarshalJSON ΒΆ added in v0.10.0
func (scp *StringWithCollectionPage) MarshalJSON() ([]byte, error)
func (*StringWithCollectionPage) UnmarshalJSON ΒΆ added in v0.10.0
func (scp *StringWithCollectionPage) UnmarshalJSON(data []byte) error
Implements https://golang.org/pkg/encoding/json/#Unmarshaler
type StringWithOrderedCollection ΒΆ
type StringWithOrderedCollection struct {
OrdCollection OrderedCollection
URL string
}
StringWithOrderedCollection can store a string URL pointing to an OrderedCollection, which can itself be stored in the struct
func (*StringWithOrderedCollection) MarshalJSON ΒΆ
func (soc *StringWithOrderedCollection) MarshalJSON() ([]byte, error)
func (*StringWithOrderedCollection) String ΒΆ
func (soc *StringWithOrderedCollection) String() string
Implements https://golang.org/pkg/fmt/#Stringer
func (*StringWithOrderedCollection) UnmarshalJSON ΒΆ
func (soc *StringWithOrderedCollection) UnmarshalJSON(data []byte) error
Implements https://golang.org/pkg/encoding/json/#Unmarshaler
type StringWithOrderedCollectionPage ΒΆ added in v0.8.0
type StringWithOrderedCollectionPage struct {
OrdCollectionPage OrderedCollectionPage
URL string
}
StringWithOrderedCollectionPage can store a string URL pointing to an OrderedCollectionPage, which can itself be stored in the struct
func (*StringWithOrderedCollectionPage) MarshalJSON ΒΆ added in v0.10.0
func (socp *StringWithOrderedCollectionPage) MarshalJSON() ([]byte, error)
func (*StringWithOrderedCollectionPage) UnmarshalJSON ΒΆ added in v0.10.0
func (socp *StringWithOrderedCollectionPage) UnmarshalJSON(data []byte) error
Implements https://golang.org/pkg/encoding/json/#Unmarshaler
type TentativeAccept ΒΆ
type TentativeAccept = Accept
type TentativeReject ΒΆ
type TentativeReject = Reject
type Travel ΒΆ
type Travel = IntransitiveActivity