Code Monkey home page Code Monkey logo

activitypub's Introduction

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

activitypub's People

Contributors

mariusor avatar gusted avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.