act

package module
v0.0.0-...-5eab768 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2025 License: MIT Imports: 9 Imported by: 0

README

go-act

Package act provides an implementation of the ActivityPub and ActivityStreams protocols, as they are used on the Fediverse, for the Go programming language.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-act

GoDoc

Import

To import package act use import code like the follownig:

import "github.com/reiver/go-act"

Installation

To install package act do the following:

GOPROXY=direct go get github.com/reiver/go-act

Author

Package act was written by Charles Iliya Krempeaux

Documentation

Index

Constants

View Source
const ContentTypeActivity string = "application/activity+json"

Variables

This section is empty.

Functions

func Marshal

func Marshal(values ...any) ([]byte, error)

func ServeActivity

func ServeActivity(responseWriter http.ResponseWriter, request *http.Request, activity []byte)

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"`
	Shares                     opt.Optional[string] `json:"shares,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"`

	// sharedInbox
	//
	// 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 (
	"github.com/reiver/go-act/ns/ap"
	"github.com/reiver/go-jsonld"
)

// ...

var actor ap.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 (
	"github.com/reiver/go-act/ns/ap"
	"github.com/reiver/go-act/ns/toot"
	"github.com/reiver/go-jsonld"
)

// ...

var actor ap.Actor
var toot toot.Toot

// ...

bytes, err := jsonld.Marshal(activitypub, toot)

type Attachment

type Attachment any

type Audience

type Audience struct {
	Name opt.Optional[string] `json:"name,omitempty"`
	Type opt.Optional[string] `json:"type,omitempty"`
	URL  opt.Optional[string] `json:"url,omitempty"`
}

type Generator

type Generator struct {
	Name opt.Optional[string] `json:"name,omitempty"`
	Type opt.Optional[string] `json:"type,omitempty"`
	URL  opt.Optional[string] `json:"url,omitempty"`
}

type HashTag

type HashTag struct {
	HRef opt.Optional[string] `json:"href,omitempty"`
	Name opt.Optional[string] `json:"name,omitempty"`
	Type json.Const[string]   `json:"type,omitempty" json.value:"Hashtag"`
}

type Icon

type Icon = Image

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"`
}

func (Image) IsEmpty

func (receiver Image) IsEmpty() bool

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 Object

type Object struct {
	NameSpace jsonld.NameSpace `jsonld:"https://www.w3.org/ns/activitystreams"`
	Prefix    jsonld.Prefix    `jsonld:"as"`

	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"`
	Summary     opt.Optional[string] `json:"summary,omitempty"`
	Tag         []HashTag            `json:"tag,omitempty"`
	Type        opt.Optional[string] `json:"type,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 (
	"github.com/reiver/go-act/ns/as"
	"github.com/reiver/go-jsonld"
)

// ...

var object as.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 (
	"github.com/reiver/go-act/ns/ap"
	"github.com/reiver/go-act/ns/as"
	"github.com/reiver/go-act/ns/toot"
	"github.com/reiver/go-jsonld"
)

// ...

var actor ap.Actor
var object as.Object
var toot toot.Toot

// ...

bytes, err := jsonld.Marshal(activitypub, 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 Outbox

type Outbox = OrderedCollection

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
}

https://www.w3.org/ns/activitystreams#Person

func (Person) IsEmpty

func (receiver Person) IsEmpty() bool

Directories

Path Synopsis
ns
as

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL