Debian Codegraph @

/

0 files · 0 symbols
README (full)

About GoActivityPub: Vocabulary

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 contains data types for most of the Activity Vocabulary and the ActivityPub extension. They are documented accordingly with annotations from these specifications.

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/[email protected]

For patches and bug reports please use the dev mailing list: ~mariusor/[email protected]

Usage

import vocab "github.com/go-ap/activitypub"

follow := vocab.Activity{
    Type: vocab.FollowType,
    Actor: vocab.IRI("https://example.com/alice"),
    Object: vocab.IRI("https://example.com/janedoe"),
}

Note about generics

The module contains helper functions which make it simpler to deal with the vocab.Item interfaces and they come in two flavours: explicit OnXXX and ToXXX functions corresponding to each type and, a generic pair of functions On[T] and To[T].

import (
    "fmt"

    vocab "github.com/go-ap/activitypub"
)

var it vocab.Item = ... // an ActivityPub object unmarshaled from a request

err := vocab.OnActivity(it, func(act *vocab.Activity) error {
    if vocab.ContentManagementActivityTypes.Contains(act.Type) {
        fmt.Printf("This is a Content Management type activity: %q", act.Type)
    }
    return nil
})

err := vocab.On[vocab.Activity](it, func(act *vocab.Activity) error {
    if vocab.ReactionsActivityTypes.Contains(act.Type) {
        fmt.Printf("This is a Reaction type activity: %q", act.Type)
    }
    return nil
})

Before using the generic versions you should consider that they come with a pretty heavy performance penalty:

goos: linux
goarch: amd64
pkg: github.com/go-ap/activitypub
cpu: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
Benchmark_OnT_vs_On_T/OnObject-8                    752387791       1.633 ns/op
Benchmark_OnT_vs_On_T/On_T_Object-8                   4656264     261.8   ns/op
Benchmark_OnT_vs_On_T/OnActor-8                     739833261       1.596 ns/op
Benchmark_OnT_vs_On_T/On_T_Actor-8                    4035148     301.9   ns/op
Benchmark_OnT_vs_On_T/OnActivity-8                  751173854       1.604 ns/op
Benchmark_OnT_vs_On_T/On_T_Activity-8                 4062598     285.9   ns/op
Benchmark_OnT_vs_On_T/OnIntransitiveActivity-8      675824500       1.640 ns/op
Benchmark_OnT_vs_On_T/On_T_IntransitiveActivity-8     4372798     274.1   ns/op
PASS
ok  	github.com/go-ap/activitypub	11.350s
dir debian/
dir tests/
file .build.yml
file .gitignore
file LICENSE
file Makefile
file README.md
file activity.go
file activity_test.go
file actor.go
file actor_test.go
file collection.go
file collection_page.go
file collection_page_test.go
file collection_test.go
file copy.go
file copy_test.go
file decoding_gob.go
file decoding_gob_test.go
file decoding_json.go
file decoding_json_test.go
file encoding_gob.go
file encoding_gob_test.go
file encoding_json.go
file encoding_json_test.go
file extractors.go
file extractors_test.go
file flatten.go
file flatten_test.go
file go.mod
file helpers.go
file helpers_test.go
file intransitive_activity.go
file intransitive_activity_test.go
file iri.go
file iri_test.go
file item.go
file item_collection.go
file item_collection_test.go
file item_test.go
file langref.go
file langref_test.go
file languages.go
file link.go
file link_test.go
file natural_language_values.go
file natural_language_values_test.go
file object.go
file object_id.go
file object_id_test.go
file object_test.go
file ordered_collection.go
file ordered_collection_page.go
file ordered_collection_page_test.go
file ordered_collection_test.go
file place.go
file place_test.go
file profile.go
file profile_test.go
file question.go
file question_test.go
file relationship.go
file relationship_test.go
file setup_test.go
file tombstone.go
file tombstone_test.go
file typer.go
file typer_test.go
file types.go
file types_test.go