asns

package module
v0.0.0-...-1d6eedc Latest Latest
Warning

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

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

README

go-asns

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-asns

GoDoc

Import

To import package act use import code like the follownig:

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

Installation

To install package act do the following:

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

Author

Package act was written by Charles Iliya Krempeaux

Documentation

Index

Examples

Constants

View Source
const (
	ActivityTypeAccept          = "Accept"
	ActivityTypeAdd             = "Add"
	ActivityTypeAnnounce        = "Announce"
	ActivityTypeArrive          = "Arrive"
	ActivityTypeBlock           = "Block"
	ActivityTypeCreate          = "Create"
	ActivityTypeDelete          = "Delete"
	ActivityTypeDislike         = "Dislike"
	ActivityTypeFlag            = "Flag"
	ActivityTypeFollow          = "Follow"
	ActivityTypeIgnore          = "Ignore"
	ActivityTypeInvite          = "Invite"
	ActivityTypeJoin            = "Join"
	ActivityTypeLeave           = "Leave"
	ActivityTypeLike            = "Like"
	ActivityTypeListen          = "Listen"
	ActivityTypeMove            = "Move"
	ActivityTypeOffer           = "Offer"
	ActivityTypeQuestion        = "Question"
	ActivityTypeReject          = "Reject"
	ActivityTypeRead            = "Read"
	ActivityTypeRemove          = "Remove"
	ActivityTypeTentativeReject = "TentativeReject"
	ActivityTypeTentativeAccept = "TentativeAccept"
	ActivityTypeTravel          = "Travel"
	ActivityTypeUndo            = "Undo"
	ActivityTypeUpdate          = "Update"
	ActivityTypeView            = "View"
)
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-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 (
	"github.com/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       opt.Optional[string] `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
package main

import (
	"fmt"

	"github.com/reiver/go-jsonld"
	"github.com/reiver/go-opt"

	"github.com/reiver/go-asns"
)

func main() {
	var announcement = asns.Announce{
		ID:        opt.Something("https://mastodon.social/users/reiver/statuses/113962917187191012/activity"),
		Actor:     opt.Something("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 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-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 (
	"github.com/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 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