client

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

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 15 Imported by: 13

README

About GoActivityPub: Client

MIT Licensed Build Status Test Coverage Go Report Card

This project is part of the GoActivityPub library which helps with creating ActivityPub applications using the Go programming language.

It can be used to create an API client for ActivityPub servers.

It supports retrieval of ActivityPub objects and collections, but also submitting Activities to servers, either as a C2S or as a S2S client.

It can supports plugging in custom authorization logic. We usually authorize the requests with either HTTP Singatures (for server to server interactions) or OAuth2 (for client to server interactions).

You can find an expanded documentation about the whole library on SourceHut.

For discussions about the projects you can write to the discussions mailing list: ~mariusor/go-activitypub-discuss@lists.sr.ht

For patches and bug reports please use the dev mailing list: ~mariusor/go-activitypub-dev@lists.sr.ht

Documentation

Index

Constants

View Source
const (
	ContentTypeJsonLD = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`
	// ContentTypeActivityJson This specification registers the application/activity+json MIME Media Type
	// specifically for identifying documents conforming to the Activity Streams 2.0 format.
	//
	// https://www.w3.org/TR/activitystreams-core/#media-type
	ContentTypeActivityJson = `application/activity+json`
)

Variables

View Source
var UserAgent = "activitypub-go-http-client"

UserAgent value that the client uses when performing requests

Functions

This section is empty.

Types

type Basic

type Basic interface {
	CanSign
	LoadIRI(vocab.IRI) (vocab.Item, error)
	CtxLoadIRI(context.Context, vocab.IRI) (vocab.Item, error)
	ToCollection(vocab.IRI, vocab.Item) (vocab.IRI, vocab.Item, error)
	CtxToCollection(context.Context, vocab.IRI, vocab.Item) (vocab.IRI, vocab.Item, error)
}

type C

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

func New

func New(o ...OptionFn) *C

func (C) Activity

func (c C) Activity(ctx context.Context, iri vocab.IRI) (*vocab.Activity, error)

Activity

func (C) Actor

func (c C) Actor(ctx context.Context, iri vocab.IRI) (*vocab.Actor, error)

Actor

func (C) Collection

func (c C) Collection(ctx context.Context, i vocab.IRI, filters ...FilterFn) (vocab.CollectionInterface, error)

Collection

func (C) CtxGet

func (c C) CtxGet(ctx context.Context, url string) (*http.Response, error)

CtxGet wrapper over the functionality offered by the default http.Client object

func (C) CtxLoadIRI

func (c C) CtxLoadIRI(ctx context.Context, id vocab.IRI) (vocab.Item, error)

CtxLoadIRI tries to dereference an IRI and load the full ActivityPub object it represents

func (C) CtxPost

func (c C) CtxPost(ctx context.Context, url, contentType string, body io.Reader) (*http.Response, error)

CtxPost wrapper over the functionality offered by the default http.Client object

func (C) CtxToCollection

func (c C) CtxToCollection(ctx context.Context, url vocab.IRI, a vocab.Item) (vocab.IRI, vocab.Item, error)

CtxToCollection

func (C) Delete

func (c C) Delete(url, contentType string, body io.Reader) (*http.Response, error)

Delete wrapper over the functionality offered by the default http.Client object

func (*C) Do

func (c *C) Do(req *http.Request) (*http.Response, error)

func (C) Followers

func (c C) Followers(ctx context.Context, actor vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)

Followers

func (C) Following

func (c C) Following(ctx context.Context, actor vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)

Following

func (C) Get

func (c C) Get(url string) (*http.Response, error)

Get wrapper over the functionality offered by the default http.Client object

func (C) Head

func (c C) Head(url string) (*http.Response, error)

Head

func (C) Inbox

func (c C) Inbox(ctx context.Context, actor vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)

Inbox

func (C) Liked

func (c C) Liked(ctx context.Context, actor vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)

Liked

func (C) Likes

func (c C) Likes(ctx context.Context, object vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)

Likes

func (C) LoadIRI

func (c C) LoadIRI(id vocab.IRI) (vocab.Item, error)

LoadIRI tries to dereference an IRI and load the full ActivityPub object it represents

func (C) Object

func (c C) Object(ctx context.Context, iri vocab.IRI) (*vocab.Object, error)

Object

func (C) Outbox

func (c C) Outbox(ctx context.Context, actor vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)

Outbox

func (C) Post

func (c C) Post(url, contentType string, body io.Reader) (*http.Response, error)

Post wrapper over the functionality offered by the default http.Client object

func (C) Put

func (c C) Put(url, contentType string, body io.Reader) (*http.Response, error)

Put wrapper over the functionality offered by the default http.Client object

func (C) Replies

func (c C) Replies(ctx context.Context, object vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)

Replies

func (C) Shares

func (c C) Shares(ctx context.Context, object vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)

Shares

func (*C) SignFn

func (c *C) SignFn(fn RequestSignFn)

func (C) ToCollection

func (c C) ToCollection(url vocab.IRI, a vocab.Item) (vocab.IRI, vocab.Item, error)

ToCollection

func (C) ToInbox

func (c C) ToInbox(ctx context.Context, a vocab.Item) (vocab.IRI, vocab.Item, error)

func (C) ToOutbox

func (c C) ToOutbox(ctx context.Context, a vocab.Item) (vocab.IRI, vocab.Item, error)

type CanSign

type CanSign interface {
	SignFn(fn RequestSignFn)
}

type Ctx

type Ctx = lw.Ctx

type CtxLogFn

type CtxLogFn func(...Ctx) LogFn

type ErrorHandlerFunc

type ErrorHandlerFunc func(...error) http.HandlerFunc

ErrorHandlerFunc is a data type for the default ErrorHandler function of the package

var ErrorHandler ErrorHandlerFunc = func(errors ...error) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		output := bytes.Buffer{}
		for i, e := range errors {
			output.WriteString(fmt.Sprintf("#%d %s\n", i, e.Error()))
		}
		w.WriteHeader(http.StatusInternalServerError)
		w.Header().Add("Content-Type", "text/plain")
		w.Write(output.Bytes())
	}
}

ErrorHandler is the error handler callback for the ActivityPub package. It can be overloaded from the packages that require it

type FilterFn

type FilterFn func() url.Values

type LogFn

type LogFn func(string, ...interface{})

type OptionFn

type OptionFn func(s *C) error

OptionFn

func SetDefaultHTTPClient

func SetDefaultHTTPClient() OptionFn

SetDefaultHTTPClient is a hacky solution to modify the default static instance of the http.DefaultClient to whatever we have instantiated currently. This ensures that options like SkipTLSValidation propagate to the requests that are not done explicitly by us, because we assume it will be executed under the same constraints.

func SkipTLSValidation

func SkipTLSValidation(skip bool) OptionFn

SkipTLSValidation

func WithHTTPClient

func WithHTTPClient(h *http.Client) OptionFn

WithHTTPClient sets the http client

func WithLogger

func WithLogger(l lw.Logger) OptionFn

func WithSignFn

func WithSignFn(fn RequestSignFn) OptionFn

WithSignFn

type PubClient

type PubClient interface {
	PubGetter
	PubSubmitter
}

type PubGetter

type PubGetter interface {
	Inbox(ctx context.Context, actor vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)
	Outbox(ctx context.Context, actor vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)
	Following(ctx context.Context, actor vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)
	Followers(ctx context.Context, actor vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)
	Likes(ctx context.Context, object vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)
	Liked(ctx context.Context, actor vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)
	Replies(ctx context.Context, object vocab.Item, filters ...FilterFn) (vocab.CollectionInterface, error)
	Collection(ctx context.Context, i vocab.IRI, filters ...FilterFn) (vocab.CollectionInterface, error)

	Actor(ctx context.Context, iri vocab.IRI) (*vocab.Actor, error)
	Activity(ctx context.Context, iri vocab.IRI) (*vocab.Activity, error)
	Object(ctx context.Context, iri vocab.IRI) (*vocab.Object, error)
}

type PubSubmitter

type PubSubmitter interface {
	ToOutbox(ctx context.Context, a vocab.Item) (vocab.IRI, vocab.Item, error)
	ToInbox(ctx context.Context, a vocab.Item) (vocab.IRI, vocab.Item, error)
}

type RequestSignFn

type RequestSignFn func(*http.Request) error

Jump to

Keyboard shortcuts

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