Debian Codegraph @

README.md

raw symbols SCIP
1 # About GoActivityPub: Vocabulary
2
3 [![MIT Licensed](https://img.shields.io/github/license/go-ap/activitypub.svg)](https://raw.githubusercontent.com/go-ap/activitypub/master/LICENSE)
4 [![Build Status](https://builds.sr.ht/~mariusor/activitypub.svg)](https://builds.sr.ht/~mariusor/activitypub)
5 [![Test coverage](https://img.shields.io/coverallsCoverage/github/go-ap/activitypub)](https://coveralls.io/github/go-ap/activitypub)
6 [![Go Report Card](https://goreportcard.com/badge/github.com/go-ap/activitypub)](https://goreportcard.com/report/github.com/go-ap/activitypub)
7
8 This project is part of the [GoActivityPub](https://github.com/go-ap) library which helps with creating ActivityPub applications using the Go programming language.
9
10 It contains data types for most of the [Activity Vocabulary](https://www.w3.org/TR/activitystreams-vocabulary/) and the [ActivityPub](https://www.w3.org/TR/activitypub/) extension.
11 They are documented accordingly with annotations from these specifications.
12
13 You can find an expanded documentation about the whole library [on SourceHut](https://man.sr.ht/~mariusor/go-activitypub/go-ap/index.md).
14
15 For discussions about the projects you can write to the discussions mailing list: [~mariusor/[email protected]](mailto:~mariusor/[email protected])
16
17 For patches and bug reports please use the dev mailing list: [~mariusor/[email protected]](mailto:~mariusor/[email protected])
18
19 ## Usage
20
21 ```go
22 import vocab "github.com/go-ap/activitypub"
23
24 follow := vocab.Activity{
25 Type: vocab.FollowType,
26 Actor: vocab.IRI("https://example.com/alice"),
27 Object: vocab.IRI("https://example.com/janedoe"),
28 }
29
30 ```
31
32 ## Note about generics
33
34 The module contains helper functions which make it simpler to deal with the `vocab.Item`
35 interfaces and they come in two flavours: explicit `OnXXX` and `ToXXX` functions corresponding
36 to each type and, a generic pair of functions `On[T]` and `To[T]`.
37
38 ```go
39 import (
40 "fmt"
41
42 vocab "github.com/go-ap/activitypub"
43 )
44
45 var it vocab.Item = ... // an ActivityPub object unmarshaled from a request
46
47 err := vocab.OnActivity(it, func(act *vocab.Activity) error {
48 if vocab.ContentManagementActivityTypes.Contains(act.Type) {
49 fmt.Printf("This is a Content Management type activity: %q", act.Type)
50 }
51 return nil
52 })
53
54 err := vocab.On[vocab.Activity](it, func(act *vocab.Activity) error {
55 if vocab.ReactionsActivityTypes.Contains(act.Type) {
56 fmt.Printf("This is a Reaction type activity: %q", act.Type)
57 }
58 return nil
59 })
60
61 ```
62
63 Before using the generic versions you should consider that they come with a pretty heavy performance penalty:
64
65 ```
66 goos: linux
67 goarch: amd64
68 pkg: github.com/go-ap/activitypub
69 cpu: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
70 Benchmark_OnT_vs_On_T/OnObject-8 752387791 1.633 ns/op
71 Benchmark_OnT_vs_On_T/On_T_Object-8 4656264 261.8 ns/op
72 Benchmark_OnT_vs_On_T/OnActor-8 739833261 1.596 ns/op
73 Benchmark_OnT_vs_On_T/On_T_Actor-8 4035148 301.9 ns/op
74 Benchmark_OnT_vs_On_T/OnActivity-8 751173854 1.604 ns/op
75 Benchmark_OnT_vs_On_T/On_T_Activity-8 4062598 285.9 ns/op
76 Benchmark_OnT_vs_On_T/OnIntransitiveActivity-8 675824500 1.640 ns/op
77 Benchmark_OnT_vs_On_T/On_T_IntransitiveActivity-8 4372798 274.1 ns/op
78 PASS
79 ok github.com/go-ap/activitypub 11.350s
80 ```