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 Endpoint
- type EndpointsOrString
- 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
Target *ObjectOrLinkOrString `json:"target,omitempty"`
Result *ObjectOrLinkOrString `json:"result,omitempty"`
Origin *ObjectOrLinkOrString `json:"origin,omitempty"`
Instrument *ObjectOrLinkOrString `json:"instrument,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 | PublicKey | Question
}
ActivityStreamer is a generic type constraint representing all valid Activity Streams 2.0 types
type Actor ¶
type Actor struct {
Object
PublicKey *PublicKey `json:"publicKey,omitempty"`
Inbox *StringWithOrderedCollectionPage `json:"inbox,omitempty"`
Outbox *StringWithOrderedCollectionPage `json:"outbox,omitempty"`
Followers *StringWithOrderedCollectionPage `json:"followers,omitempty"`
Following *StringWithOrderedCollectionPage `json:"following,omitempty"`
Liked *StringWithOrderedCollectionPage `json:"liked,omitempty"`
Streams *ObjectOrLinkOrString `json:"streams,omitempty"`
PreferredUsername string `json:"preferredUsername,omitempty"`
ManuallyApprovesFollowers bool `json:"manuallyApprovesFollowers,omitempty"`
EndpointsOrURI *EndpointsOrString `json:"endpoints,omitempty"`
}
type Arrive ¶
type Arrive = IntransitiveActivity
type Collection ¶
type Collection struct {
Object
TotalItems int `json:"totalItems,omitempty"`
Current *ObjectOrLinkOrString `json:"current,omitempty"`
First *ObjectOrLinkOrString `json:"first,omitempty"`
Last *ObjectOrLinkOrString `json:"last,omitempty"`
Items *ObjectOrLinkOrString `json:"items,omitempty"`
}
Collection is provided for spec compliance, prefer OrderedCollection
func (*Collection) MarshalJSON ¶ added in v0.7.0
func (col *Collection) MarshalJSON() ([]byte, error)
type CollectionPage ¶
type CollectionPage struct {
Collection
PartOf *ObjectOrLinkOrString `json:"partOf,omitempty"`
Next *ObjectOrLinkOrString `json:"next,omitempty"`
Prev *ObjectOrLinkOrString `json:"prev,omitempty"`
}
CollectionPage is provided for spec compliance, prefer OrderedCollectionPage
func (*CollectionPage) MarshalJSON ¶ added in v0.7.0
func (colp *CollectionPage) MarshalJSON() ([]byte, error)
type Endpoint ¶
type Endpoint struct {
ProxyUrl string `json:"proxyUrl,omitempty"`
OauthAuthorizationEndpoint string `json:"oauthAuthorizationEndpoint,omitempty"`
OauthTokenEndpoint string `json:"oauthTokenEndpoint,omitempty"`
ProvideClientKey string `json:"provideClientKey,omitempty"`
SignClientKey string `json:"signClientKey,omitempty"`
}
type EndpointsOrString ¶ added in v0.3.0
func (*EndpointsOrString) MarshalJSON ¶ added in v0.3.0
func (enp *EndpointsOrString) MarshalJSON() ([]byte, error)
func (*EndpointsOrString) String ¶ added in v0.3.0
func (enp *EndpointsOrString) String() string
Implements https://golang.org/pkg/fmt/#Stringer
func (*EndpointsOrString) UnmarshalJSON ¶ added in v0.3.0
func (enp *EndpointsOrString) UnmarshalJSON(data []byte) error
Implements https://golang.org/pkg/encoding/json/#Unmarshaler
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"`
Target *ObjectOrLinkOrString `json:"target,omitempty"`
Result *ObjectOrLinkOrString `json:"result,omitempty"`
Origin *ObjectOrLinkOrString `json:"origin,omitempty"`
Instrument *ObjectOrLinkOrString `json:"instrument,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 *ObjectOrLinkOrString `json:"@context,omitempty"`
ASLanguage string `json:"@language,omitempty"`
Type string `json:"type"`
Href string `json:"href,omitempty"`
Hreflang string `json:"hreflang,omitempty"`
Rel []string `json:"rel,omitempty"`
MediaType string `json:"mediaType,omitempty"`
Height int `json:"height,omitempty"`
Width int `json:"width,omitempty"`
Name string `json:"name,omitempty"`
NameMap map[string]string `json:"nameMap,omitempty"`
Value string `json:"value,omitempty"`
Preview *ObjectOrLinkOrString `json:"preview,omitempty"`
Published *time.Time `json:"published,omitempty"`
}
Link represents the base ActivityStreams Link and all of its properties Other Link types extend it
type Location ¶
type Location struct {
Object
Longitude float32 `json:"longitude,omitempty"`
Latitude float32 `json:"latitude,omitempty"`
Altitude int `json:"altitude,omitempty"`
Units string `json:"units,omitempty"`
}
func (*Location) String ¶
Implements https://golang.org/pkg/fmt/#Stringer
type Object ¶
type Object struct {
ASContext *ObjectOrLinkOrString `json:"@context,omitempty"`
ASLanguage string `json:"@language,omitempty"`
Schema string `json:"schema,omitempty"`
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
AtType string `json:"@type,omitempty"`
Summary string `json:"summary,omitempty"`
SummaryMap map[string]string `json:"summaryMap,omitempty"`
AtID string `json:"@id,omitempty"`
Name string `json:"name,omitempty"`
NameMap map[string]string `json:"nameMap,omitempty"`
AlsoKnownAs *ObjectOrLinkOrString `json:"alsoKnownAs,omitempty"`
MovedTo *ObjectOrLinkOrString `json:"movedTo,omitempty"`
Attachment *ObjectOrLinkOrString `json:"attachment,omitempty"`
AttributedTo *ObjectOrLinkOrString `json:"attributedTo,omitempty"`
Audience *ObjectOrLinkOrString `json:"audience,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"`
Source *ObjectOrLinkOrString `json:"source,omitempty"`
Context *ObjectOrLinkOrString `json:"context,omitempty"`
StartTime *time.Time `json:"startTime,omitempty"`
EndTime *time.Time `json:"endTime,omitempty"`
Generator *ObjectOrLinkOrString `json:"generator,omitempty"`
Featured *ObjectOrLinkOrString `json:"featured,omitempty"`
Likes *ObjectOrLinkOrString `json:"likes,omitempty"`
Icon *ObjectOrLinkOrString `json:"icon,omitempty"`
Image *ObjectOrLinkOrString `json:"image,omitempty"`
InReplyTo *ObjectOrLinkOrString `json:"inReplyTo,omitempty"`
Location *ObjectOrLinkOrString `json:"location,omitempty"`
Preview *ObjectOrLinkOrString `json:"preview,omitempty"`
Published *time.Time `json:"published,omitempty"`
Replies *OrderedCollection `json:"replies,omitempty"`
Tag *ObjectOrLinkOrString `json:"tag,omitempty"`
Updated *time.Time `json:"updated,omitempty"`
URL *ObjectOrLinkOrString `json:"url,omitempty"`
To *ObjectOrLinkOrString `json:"to,omitempty"`
Bto *ObjectOrLinkOrString `json:"bto,omitempty"`
Cc *ObjectOrLinkOrString `json:"cc,omitempty"`
Bcc *ObjectOrLinkOrString `json:"bcc,omitempty"`
MediaType string `json:"mediaType,omitempty"`
Duration string `json:"duration,omitempty"` // xsd:duration
}
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 {
URL []string
Target ObjectOrLink
}
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
TotalItems int `json:"totalItems"`
Current *ObjectOrLinkOrString `json:"current,omitempty"`
First *ObjectOrLinkOrString `json:"first,omitempty"`
Last *ObjectOrLinkOrString `json:"last,omitempty"`
OrderedItems *ObjectOrLinkOrString `json:"orderedItems"`
}
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
PartOf *ObjectOrLinkOrString `json:"partOf,omitempty"`
Next *ObjectOrLinkOrString `json:"next,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
OneOf *ObjectOrLinkOrString `json:"oneOf,omitempty"`
AnyOf *ObjectOrLinkOrString `json:"anyOf,omitempty"`
Closed *time.Time `json:"closed,omitempty"`
}
type Relationship ¶
type Relationship struct {
Object
Subject *ObjectOrLinkOrString `json:"subject,omitempty"`
Relationship string `json:"relationship,omitempty"`
RelationshipObject *ObjectOrLinkOrString `json:"object"`
}
type StringWithCollection ¶
type StringWithCollection struct {
URL string
Collection Collection
}
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 {
URL string
CollectionPage CollectionPage
}
StringWithCollectionPage can store a string URL pointing to a CollectionPage, which can itself be stored in the struct
type StringWithOrderedCollection ¶
type StringWithOrderedCollection struct {
URL string
OrdCollection OrderedCollection
}
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 {
URL string
OrdCollectionPage OrderedCollectionPage
}
StringWithOrderedCollectionPage can store a string URL pointing to an OrderedCollectionPage, which can itself be stored in the struct
type TentativeAccept ¶
type TentativeAccept = Accept
type TentativeReject ¶
type TentativeReject = Reject
type Travel ¶
type Travel = IntransitiveActivity