activityserve

package module
v0.0.0-...-d7ab3ea Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 24 Imported by: 4

README

ActivityServe

A very light ActivityPub library in go

This library was built to support the very little functions that pherephone requires. It might never be feature-complete but it's a very good point to start your activityPub journey. Take a look at activityserve-example for a simple main file that uses activityserve to post a "Hello, world" message.

For now it supports following and unfollowing users, accepting follows, announcing (boosting) other posts and this is pretty much it.

The library is still a moving target and the api is not guaranteed to be stable.

You can override the auto-accept upon follow by setting the actor.OnFollow to a custom function.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatHeaders

func FormatHeaders(header http.Header) string

FormatHeaders to string for printing

func FormatJSON

func FormatJSON(theJSON []byte) string

FormatJSON formats json with tabs and returns the new string

func PrettyPrint

func PrettyPrint(themap map[string]interface{})

PrettyPrint maps

func PrettyPrintJSON

func PrettyPrintJSON(theJSON []byte)

PrettyPrintJSON does what it's name says

func ReadLines

func ReadLines(filename string, from, to int) (lines []string, err error)

ReadLines reads specific lines from a file and returns them as an array of strings

func Serve

func Serve(actors map[string]Actor)

Serve starts an http server with all the required handlers

func ServeSingleActor

func ServeSingleActor(actor Actor)

ServeSingleActor just simplifies the call from main so that onboarding is as easy as possible

func Setup

func Setup(configurationFile string, debug bool) *ini.File

Setup sets our environment up

func SetupStorage

func SetupStorage(storage string)

SetupStorage creates storage

Types

type Actor

type Actor struct {
	Name string

	OnFollow         func(map[string]interface{})
	OnReceiveContent func(map[string]interface{})
	// contains filtered or unexported fields
}

Actor represents a local actor we can act on behalf of.

func GetActor

func GetActor(name, summary, actorType string) (Actor, error)

GetActor attempts to LoadActor and if it doesn't exist creates one

func LoadActor

func LoadActor(name string) (Actor, error)

LoadActor searches the filesystem and creates an Actor from the data in <name>.json This does not preserve events so use with caution

func MakeActor

func MakeActor(name, summary, actorType string) (Actor, error)

MakeActor creates and returns a new local actor we can act on behalf of. It also creates its files on disk

func (*Actor) Accept

func (a *Actor) Accept(follow map[string]interface{})

Accept a follow request

func (*Actor) Announce

func (a *Actor) Announce(url string)

Announce this activity to our followers

func (*Actor) CreateNote

func (a *Actor) CreateNote(content, inReplyTo string)

CreateNote posts an activityPub note to our followers

func (*Actor) Follow

func (a *Actor) Follow(user string) (err error)

Follow a remote user by their iri

func (*Actor) Followers

func (a *Actor) Followers() map[string]string

Followers returns the list of followers

func (*Actor) Following

func (a *Actor) Following() map[string]string

Following returns the list of followers

func (*Actor) GetFollowers

func (a *Actor) GetFollowers(page int) (response []byte, err error)

GetFollowers returns a list of people that follow us

func (*Actor) GetFollowing

func (a *Actor) GetFollowing(page int) (response []byte, err error)

GetFollowing returns a list of people that we follow

func (*Actor) GetOutboxIRI

func (a *Actor) GetOutboxIRI() *url.URL

GetOutboxIRI returns the outbox iri in net/url format

func (*Actor) NewFollower

func (a *Actor) NewFollower(iri string, inbox string) error

NewFollower records a new follower to the actor file

func (*Actor) Unfollow

func (a *Actor) Unfollow(user string)

Unfollow the user declared by the iri in `user` this recreates the original follow activity , wraps it in an Undo activity, sets it's id to the id of the original Follow activity that was accepted when initially following that user (this is read from the `actor.following` map

type ActorToSave

type ActorToSave struct {
	Name, Summary, ActorType, IRI, PublicKey, PrivateKey string
	Followers, Following, Rejected, Requested            map[string]interface{}
}

ActorToSave is a stripped down actor representation with exported properties in order for json to be able to marshal it. see https://stackoverflow.com/questions/26327391/json-marshalstruct-returns

type RemoteActor

type RemoteActor struct {
	// contains filtered or unexported fields
}

RemoteActor is a type that holds an actor that we want to interact with

func NewRemoteActor

func NewRemoteActor(iri string) (RemoteActor, error)

NewRemoteActor returns a remoteActor which holds all the info required for an actor we want to interact with (not essentially sitting in our instance)

func (RemoteActor) GetInbox

func (ra RemoteActor) GetInbox() string

GetInbox returns the inbox url of the actor

func (RemoteActor) GetSharedInbox

func (ra RemoteActor) GetSharedInbox() string

GetSharedInbox returns the inbox url of the actor

Jump to

Keyboard shortcuts

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