Documentation
¶
Index ¶
- Constants
- func Marshal(values ...any) ([]byte, error)
- func ServeActivity(responseWriter http.ResponseWriter, request *http.Request, activity []byte)
- type Actor
- type Announce
- type AnyObject
- type Article
- type Attachment
- type Audience
- type Generator
- type HashTag
- type Icon
- type Image
- type Location
- type Note
- type Object
- type OrderedCollection
- type OrderedCollectionPage
- type Outbox
- type Page
- type Person
- type Strings
- type Thing
Examples ¶
Constants ¶
const ( TypeAccept = "Accept" TypeAdd = "Add" TypeAnnounce = "Announce" TypeArrive = "Arrive" TypeBlock = "Block" TypeCreate = "Create" TypeDelete = "Delete" TypeDislike = "Dislike" TypeFlag = "Flag" TypeFollow = "Follow" TypeIgnore = "Ignore" TypeInvite = "Invite" TypeJoin = "Join" TypeLeave = "Leave" TypeLike = "Like" TypeListen = "Listen" TypeMove = "Move" TypeOffer = "Offer" TypeQuestion = "Question" TypeReject = "Reject" TypeRead = "Read" TypeRemove = "Remove" TypeTentativeReject = "TentativeReject" TypeTentativeAccept = "TentativeAccept" TypeTravel = "Travel" TypeUndo = "Undo" TypeUpdate = "Update" TypeView = "View" )
const ( TypeApplication = "Application" TypeFeed = "Feed" TypeGroup = "Group" TypeOrganization = "Organization" TypePerson = "Person" TypeService = "Service" )
const ( TypeArticle = "Article" TypeAudio = "Audio" TypeDocument = "Document" TypeEvent = "Event" TypeImage = "Image" TypeNote = "Note" TypePage = "Page" TypePlace = "Place" TypeProfile = "Profile" TypeRelationship = "Relationship" TypeTombstone = "Tombstone" TypeVideo = "Video" )
const ContentType string = "application/activity+json"
const (
TypeActivity = "Activity"
)
const (
TypeActor = "Actor"
)
const (
TypeLink = "Link"
)
const (
TypeMention = "Mention"
)
const (
TypeObject = "Object"
)
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
Marshal returns the merged JSON-LD of the values passed to it.
Marshal is just a wrapper around jsonld.Marshal.
func ServeActivity ¶
func ServeActivity(responseWriter http.ResponseWriter, request *http.Request, activity []byte)
ServeActivity helps create an http.Handler that serves "application/activity+json".
For example:
func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) { // ... asns.ServeActivity(responseWriter, request, data) // ... }
Types ¶
type Actor ¶
type Actor struct { NameSpace jsonld.NameSpace `jsonld:"https://www.w3.org/ns/activitystreams"` Prefix jsonld.Prefix `jsonld:"as"` EndPoints opt.Optional[string] `json:"endpoints,omitempty"` Following opt.Optional[string] `json:"following,omitempty"` Followers opt.Optional[string] `json:"followers,omitempty"` // inbox // // A reference to an ActivityStreams (1) OrderedCollection (2) comprised of all the messages received by the actor; see 5.2 Inbox (3). // // (1) https://www.w3.org/TR/activitystreams-core/ // // (2) https://www.w3.org/TR/activitystreams-vocabulary/#dfn-orderedcollection // // (3) https://www.w3.org/TR/activitypub/#inbox Inbox opt.Optional[string] `json:"inbox,omitempty"` Liked opt.Optional[string] `json:"liked,omitempty"` Likes opt.Optional[string] `json:"likes,omitempty"` OauthAuthorizationEndPoint opt.Optional[string] `json:"oauthAuthorizationEndpoint,omitempty"` OauthTokenEndPoint opt.Optional[string] `json:"oauthTokenEndpoint,omitempty"` // outbox // // An ActivityStreams (1) OrderedCollection (2) comprised of all the messages produced by the actor; see 5.1 Outbox (3). // // (1) https://www.w3.org/TR/activitystreams-core/ // // (2) https://www.w3.org/TR/activitystreams-vocabulary/#dfn-orderedcollection // // (3) https://www.w3.org/TR/activitypub/#outbox Outbox opt.Optional[string] `json:"outbox,omitempty"` // preferredUsername // // A short username which may be used to refer to the actor, with no uniqueness guarantees. PreferredUserName opt.Optional[string] `json:"preferredUsername,omitempty"` ProvideClientKey opt.Optional[string] `json:"provideClientKey,omitempty"` ProxyURL opt.Optional[string] `json:"proxyUrl,omitempty"` // // An optional endpoint used for wide delivery of publicly addressed activities and activities sent to followers. (1) // sharedInbox endpoints SHOULD also be publicly readable OrderedCollection objects containing objects addressed to the Public (2) special collection. Reading from the sharedInbox endpoint MUST NOT present objects which are not addressed to the Public endpoint. // // (1) https://www.w3.org/TR/activitypub/#shared-inbox-delivery // // (2) https://www.w3.org/TR/activitypub/#public-addressing SharedInbox opt.Optional[string] `json:"sharedInbox,omitempty"` SignClientKey opt.Optional[string] `json:"signClientKey,omitempty"` Source opt.Optional[string] `json:"source,omitempty"` Streams opt.Optional[string] `json:"streams,omitempty"` UploadMedia opt.Optional[string] `json:"uploadMedia,omitempty"` }
Actor represents the ActivityPub actor object name-space used in a JSON-LD document.
Reference: https://www.w3.org/TR/activitypub/#actor-objects
Example usage:
import ( "codeberg.org/reiver/go-asns" "github.com/reiver/go-jsonld" ) // ... var actor asns.Actor // ... bytes, err := jsonld.Marshal(actor)
More likely you would mix this with other JSON-LD name-spaces, with code similar to the following:
import ( "codeberg.org/reiver/go-asns" "github.com/reiver/go-tootns" "github.com/reiver/go-jsonld" ) // ... var actor asns.Actor var toot tootns.Toot // ... bytes, err := jsonld.Marshal(actor, toot)
type Announce ¶
type Announce struct { NameSpace jsonld.NameSpace `jsonld:"https://www.w3.org/ns/activitystreams"` Prefix jsonld.Prefix `jsonld:"as"` Actor jsonld.Strings `json:"actor,omitempty"` AlsoKnownAs []string `json:"alsoKnownAs,omitempty"` Attachment []Attachment `json:"attachment,omitempty"` Content opt.Optional[string] `json:"content,omitempty"` ID opt.Optional[string] `json:"id,omitempty"` Image Image `json:"image,omitempty"` Icon Icon `json:"icon,omitempty"` MediaType opt.Optional[string] `json:"mediaType,omitempty"` MovedTo opt.Optional[string] `json:"movedTo,omitempty"` Name opt.Optional[string] `json:"name,omitempty"` Object opt.Optional[string] `json:"object,omitempty"` Published opt.Optional[string] `json:"published,omitempty"` Summary opt.Optional[string] `json:"summary,omitempty"` Tag []HashTag `json:"tag,omitempty"` Target opt.Optional[string] `json:"target,omitempty"` To []string `json:"to,omitempty"` Type json.Const[string] `json:"type" json.value:"Announce"` URL opt.Optional[string] `json:"url,omitempty"` }
Example ¶
var announcement = asns.Announce{ ID: opt.Something("https://mastodon.social/users/reiver/statuses/113962917187191012/activity"), Actor: jsonld.SomeString("acct:reiver@mastodon.social"), Published: opt.Something("2025-02-07T14:56:43Z"), To: []string{"https://www.w3.org/ns/activitystreams#Public"}, Object: opt.Something("https://example.com/note/0xf1938e3a1a6f4ac790fdf66d1b167858"), } bytes, err := jsonld.Marshal(announcement) if nil != err { fmt.Printf("ERROR: %s", err) return } fmt.Printf("%s", bytes)
type AnyObject ¶
type AnyObject struct { NameSpace jsonld.NameSpace `jsonld:"https://www.w3.org/ns/activitystreams"` Prefix jsonld.Prefix `jsonld:"as"` Attachment []Attachment `json:"attachment,omitempty"` AttributedTo Strings `json:"attributedTo,omitempty"` Audiene Strings `json:"audience,omitempty"` CC Strings `json:"cc,omitempty"` Content opt.Optional[string] `json:"content,omitempty"` Duration opt.Optional[string] `json:"duration,omitempty"` EndTime opt.Optional[string] `json:"endTime,omitempty"` Icon Icon `json:"icon,omitempty"` ID opt.Optional[string] `json:"id,omitempty"` Image Image `json:"image,omitempty"` InReplyTo Strings `json:"inReplyTo,omitempty"` Location Location `json:"location,omitempty"` MediaType opt.Optional[string] `json:"mediaType,omitempty"` Name opt.Optional[string] `json:"name,omitempty"` Published opt.Optional[string] `json:"published,omitempty"` StartTime opt.Optional[string] `json:"startTime,omitempty"` Summary opt.Optional[string] `json:"summary,omitempty"` Tag []HashTag `json:"tag,omitempty"` To Strings `json:"to,omitempty"` Type Strings `json:"type,omitempty"` Updated opt.Optional[string] `json:"updated,omitempty"` URL opt.Optional[string] `json:"url,omitempty"` }
type Article ¶
type Article struct { NameSpace jsonld.NameSpace `jsonld:"https://www.w3.org/ns/activitystreams"` Prefix jsonld.Prefix `jsonld:"as"` AlsoKnownAs Strings `json:"alsoKnownAs,omitempty"` Attachment []Attachment `json:"attachment,omitempty"` AttributedTo Strings `json:"attributedTo,omitempty"` Audiene Strings `json:"audience,omitempty"` CC Strings `json:"cc,omitempty"` Content opt.Optional[string] `json:"content,omitempty"` Duration opt.Optional[string] `json:"duration,omitempty"` EndTime opt.Optional[string] `json:"endTime,omitempty"` Icon Icon `json:"icon,omitempty"` ID opt.Optional[string] `json:"id,omitempty"` Image Image `json:"image,omitempty"` InReplyTo Strings `json:"inReplyTo,omitempty"` MediaType opt.Optional[string] `json:"mediaType,omitempty"` MovedTo opt.Optional[string] `json:"movedTo,omitempty"` Name opt.Optional[string] `json:"name,omitempty"` Published opt.Optional[string] `json:"published,omitempty"` StartTime opt.Optional[string] `json:"startTime,omitempty"` Summary opt.Optional[string] `json:"summary,omitempty"` Tag []HashTag `json:"tag,omitempty"` To Strings `json:"to,omitempty"` Type json.Const[string] `json:"type" json.value:"Article"` Updated opt.Optional[string] `json:"updated,omitempty"` URL opt.Optional[string] `json:"url,omitempty"` }
Article represents an ActivityPub / ActivityStream Object type "Article".
https://www.w3.org/TR/activitystreams-vocabulary/#dfn-article
Article is similar to Object except its `Type` field is hard-coded to "Article".
type Attachment ¶
type Attachment any
type Image ¶
type Image struct { NameSpace jsonld.NameSpace `jsonld:"https://www.w3.org/ns/activitystreams"` Prefix jsonld.Prefix `jsonld:"as"` Audiences []Audience `json:"audience,omitempty"` Generator Generator `json:"generator,omitempty"` Height opt.Optional[uint64] `json:"height,omitempty"` MediaType opt.Optional[string] `json:"mediaType,omitempty"` Location Location `json:"location,omitempty"` Name opt.Optional[string] `json:"name,omitempty"` Published opt.Optional[string] `json:"published,omitempty"` Type json.Const[string] `json:"type" json.value:"Image"` Updated opt.Optional[string] `json:"updated,omitempty"` URL opt.Optional[string] `json:"url,omitempty"` Width opt.Optional[uint64] `json:"width,omitempty"` }
type Location ¶
type Location struct { Altitude opt.Optional[string] `json:"altitude,omitempty,bare"` Latitude opt.Optional[string] `json:"latitude,omitempty,bare"` Longitude opt.Optional[string] `json:"longitude,omitempty,bare"` Name opt.Optional[string] `json:"name,omitempty"` Type opt.Optional[string] `json:"type,omitempty"` Units opt.Optional[string] `json:"units,omitempty"` URL opt.Optional[string] `json:"url,omitempty"` }
type Note ¶
type Note struct { NameSpace jsonld.NameSpace `jsonld:"https://www.w3.org/ns/activitystreams"` Prefix jsonld.Prefix `jsonld:"as"` AlsoKnownAs Strings `json:"alsoKnownAs,omitempty"` Attachment []Attachment `json:"attachment,omitempty"` AttributedTo Strings `json:"attributedTo,omitempty"` Audiene Strings `json:"audience,omitempty"` CC Strings `json:"cc,omitempty"` Content opt.Optional[string] `json:"content,omitempty"` Duration opt.Optional[string] `json:"duration,omitempty"` EndTime opt.Optional[string] `json:"endTime,omitempty"` Icon Icon `json:"icon,omitempty"` ID opt.Optional[string] `json:"id,omitempty"` Image Image `json:"image,omitempty"` InReplyTo Strings `json:"inReplyTo,omitempty"` MediaType opt.Optional[string] `json:"mediaType,omitempty"` MovedTo opt.Optional[string] `json:"movedTo,omitempty"` Name opt.Optional[string] `json:"name,omitempty"` Published opt.Optional[string] `json:"published,omitempty"` StartTime opt.Optional[string] `json:"startTime,omitempty"` Summary opt.Optional[string] `json:"summary,omitempty"` Tag []HashTag `json:"tag,omitempty"` To Strings `json:"to,omitempty"` Type json.Const[string] `json:"type" json.value:"Note"` Updated opt.Optional[string] `json:"updated,omitempty"` URL opt.Optional[string] `json:"url,omitempty"` }
Note represents an ActivityPub / ActivityStream Object type "Note".
https://www.w3.org/TR/activitystreams-vocabulary/#dfn-note
Note is similar to Object except its `Type` field is hard-coded to "Note".
type Object ¶
type Object struct { NameSpace jsonld.NameSpace `jsonld:"https://www.w3.org/ns/activitystreams"` Prefix jsonld.Prefix `jsonld:"as"` AlsoKnownAs Strings `json:"alsoKnownAs,omitempty"` Attachment []Attachment `json:"attachment,omitempty"` AttributedTo Strings `json:"attributedTo,omitempty"` Audiene Strings `json:"audience,omitempty"` CC Strings `json:"cc,omitempty"` Content opt.Optional[string] `json:"content,omitempty"` Duration opt.Optional[string] `json:"duration,omitempty"` EndTime opt.Optional[string] `json:"endTime,omitempty"` Icon Icon `json:"icon,omitempty"` ID opt.Optional[string] `json:"id,omitempty"` Image Image `json:"image,omitempty"` InReplyTo Strings `json:"inReplyTo,omitempty"` MediaType opt.Optional[string] `json:"mediaType,omitempty"` MovedTo opt.Optional[string] `json:"movedTo,omitempty"` Name opt.Optional[string] `json:"name,omitempty"` Published opt.Optional[string] `json:"published,omitempty"` StartTime opt.Optional[string] `json:"startTime,omitempty"` Summary opt.Optional[string] `json:"summary,omitempty"` Tag []HashTag `json:"tag,omitempty"` To Strings `json:"to,omitempty"` Type Strings `json:"type,omitempty"` Updated opt.Optional[string] `json:"updated,omitempty"` URL opt.Optional[string] `json:"url,omitempty"` }
Object represents the ActivityStreams object name-space used in a JSON-LD document.
Reference: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object
Example usage:
import ( "codeberg.org/reiver/go-asns" "github.com/reiver/go-jsonld" ) // ... var object asns.Object // ... bytes, err := jsonld.Marshal(object)
More likely you would mix this with other JSON-LD name-spaces, with code similar to the following:
import ( "codeberg.org/reiver/go-asns" "github.com/reiver/go-tootns" "github.com/reiver/go-jsonld" ) // ... var actor asns.Actor var object asns.Object var toot tootns.Toot // ... bytes, err := jsonld.Marshal(actor, object, toot)
type OrderedCollection ¶
type OrderedCollection struct { NameSpace jsonld.NameSpace `jsonld:"https://www.w3.org/ns/activitystreams"` Prefix jsonld.Prefix `jsonld:"as"` Current opt.Optional[string] `json:"current,omitempty"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-current First opt.Optional[string] `json:"first,omitempty"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-first Icon Icon `json:"icon,omitempty"` // https://www.w3.org/ns/activitystreams#icon ID opt.Optional[string] `json:"id,omitempty"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-id Image Image `json:"image,omitempty"` // https://www.w3.org/ns/activitystreams#image Items []any `json:"items,omitempty"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-items Last opt.Optional[string] `json:"last,omitempty"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-last Name opt.Optional[string] `json:"name,omitempty"` // https://www.w3.org/ns/activitystreams#name Summary opt.Optional[string] `json:"summary,omitempty"` // https://www.w3.org/ns/activitystreams#summary TotalItems opt.Optional[uint64] `json:"totalItems,omitempty"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-totalitems Type json.Const[string] `json:"type" json.value:"OrderedCollection"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-type }
https://www.w3.org/TR/activitystreams-vocabulary/#dfn-orderedcollection
type OrderedCollectionPage ¶
type OrderedCollectionPage struct { NameSpace jsonld.NameSpace `jsonld:"https://www.w3.org/ns/activitystreams"` Prefix jsonld.Prefix `jsonld:"as"` Icon Icon `json:"icon,omitempty"` // https://www.w3.org/ns/activitystreams#icon ID opt.Optional[string] `json:"id,omitempty"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-id Image Image `json:"image,omitempty"` // https://www.w3.org/ns/activitystreams#image Name opt.Optional[string] `json:"name,omitempty"` // https://www.w3.org/ns/activitystreams#name Next opt.Optional[string] `json:"next,omitempty"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-next OrderedItems []any `json:"orderedItems"` // https://www.w3.org/TR/activitystreams-core/#h-paging PartOf opt.Optional[string] `json:"partOf,omitempty"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-partof Prev opt.Optional[string] `json:"prev,omitempty"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-prev StartIndex opt.Optional[uint64] `json:"startIndex,omitempty"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-startindex Summary opt.Optional[string] `json:"summary,omitempty"` // https://www.w3.org/ns/activitystreams#summary Type json.Const[string] `json:"type" json.value:"OrderedCollectionPage"` // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-type }
https://www.w3.org/TR/activitystreams-vocabulary/#dfn-orderedcollectionpage
type Outbox ¶
type Outbox = OrderedCollection
type Page ¶
type Page struct { NameSpace jsonld.NameSpace `jsonld:"https://www.w3.org/ns/activitystreams"` Prefix jsonld.Prefix `jsonld:"as"` AlsoKnownAs Strings `json:"alsoKnownAs,omitempty"` Attachment []Attachment `json:"attachment,omitempty"` AttributedTo Strings `json:"attributedTo,omitempty"` Audiene Strings `json:"audience,omitempty"` CC Strings `json:"cc,omitempty"` Content opt.Optional[string] `json:"content,omitempty"` Duration opt.Optional[string] `json:"duration,omitempty"` EndTime opt.Optional[string] `json:"endTime,omitempty"` Icon Icon `json:"icon,omitempty"` ID opt.Optional[string] `json:"id,omitempty"` Image Image `json:"image,omitempty"` InReplyTo Strings `json:"inReplyTo,omitempty"` MediaType opt.Optional[string] `json:"mediaType,omitempty"` MovedTo opt.Optional[string] `json:"movedTo,omitempty"` Name opt.Optional[string] `json:"name,omitempty"` Published opt.Optional[string] `json:"published,omitempty"` StartTime opt.Optional[string] `json:"startTime,omitempty"` Summary opt.Optional[string] `json:"summary,omitempty"` Tag []HashTag `json:"tag,omitempty"` To Strings `json:"to,omitempty"` Type json.Const[string] `json:"type" json.value:"Page"` Updated opt.Optional[string] `json:"updated,omitempty"` URL opt.Optional[string] `json:"url,omitempty"` }
Page represents an ActivityPub / ActivityStream Object type "Page".
https://www.w3.org/TR/activitystreams-vocabulary/#dfn-page
Page is similar to Object except its `Type` field is hard-coded to "Page".
type Person ¶
type Person struct { NameSpace jsonld.NameSpace `jsonld:"https://www.w3.org/ns/activitystreams"` Prefix jsonld.Prefix `jsonld:"as"` AlsoKnownAs []string `json:"alsoKnownAs,omitempty"` Attachments []Attachment `json:"attachment,omitempty"` // https://www.w3.org/ns/activitystreams#attachment ID opt.Optional[string] `json:"id,omitempty"` Image Image `json:"image,omitempty"` // https://www.w3.org/ns/activitystreams#image Icon Icon `json:"icon,omitempty"` // https://www.w3.org/ns/activitystreams#icon MediaType opt.Optional[string] `json:"mediaType,omitempty"` // https://www.w3.org/ns/activitystreams#mediaType MovedTo opt.Optional[string] `json:"movedTo,omitempty"` Name opt.Optional[string] `json:"name,omitempty"` // https://www.w3.org/ns/activitystreams#name Summary opt.Optional[string] `json:"summary,omitempty"` // https://www.w3.org/ns/activitystreams#summary Tag []HashTag `json:"tag,omitempty"` // https://www.w3.org/ns/activitystreams#tag Type json.Const[string] `json:"type" json.value:"Person"` URL opt.Optional[string] `json:"url,omitempty"` // https://www.w3.org/ns/activitystreams#url }
type Strings ¶
type Strings struct {
// contains filtered or unexported fields
}
Strings represents an ActivityStreams "type" field that is zero, one, or many strings.
And, the way it marshals to JSON / JSON-LD is different depending on whether it is zero, one, or many strings.
If its value is NoStrings then its JSON / JSON-LD representation is the JSON / JSON-LD: null.
If its value is SomeString then its JSON / JSON-LD representation is the JSON / JSON-LD: string.
If its value is SomeStrings then its JSON / JSON-LD representation is the JSON / JSON-LD: array (of string).
func NoStrings ¶
func NoStrings() Strings
NoStrings returns a Strings with no strings in it.
This is more-or-less similar to the concept of "none" and "nothing" with optional-types. Note that "optional-types" are also known as 'option-types' and 'maybe-types'.
func SomeString ¶
SomeString returns a Strings with one string in it.
This is more-or-less similar to the concept of "some" and "something" with optional-types. Note that "optional-types" are also known as 'option-types' and 'maybe-types'.
func SomeStrings ¶
SomeStrings returns a Strings with many strings in it.
func (Strings) MarshalJSON ¶
MarshalJSON makes Strings fit the json.Marshaler interface.
func (*Strings) UnmarshalJSON ¶
UnmarshalJSON makes Strings fit the json.Unmarshaler interface.
Source Files
¶
- activitytypes.go
- actor.go
- actortypes.go
- announce.go
- anyobject.go
- article.go
- attachment.go
- audience.go
- contenttype.go
- errors.go
- generator.go
- hashtag.go
- httperror.go
- icon.go
- image.go
- linktypes.go
- location.go
- marshal.go
- note.go
- object.go
- objecttypes.go
- orderedcollection.go
- orderedcollectionpage.go
- outbox.go
- page.go
- person.go
- serveactivity.go
- strings.go
- thing.go