Skip to main content

Go Libraries

Go libraries for implementing ActivityPub.

go-fed/activity

Comprehensive ActivityPub/ActivityStreams implementation.

PropertyValue
Repositorygithub.com/go-fed/activity
Documentationgo-fed.org
LicenseBSD-3
StatusActive

Features

  • Complete ActivityStreams vocabulary
  • ActivityPub C2S and S2S
  • HTTP Signatures
  • Extensible type system

Example

package main

import (
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab"
)

func createNote() vocab.ActivityStreamsNote {
note := streams.NewActivityStreamsNote()

// Set content
contentProp := streams.NewActivityStreamsContentProperty()
contentProp.AppendXMLSchemaString("Hello from Go!")
note.SetActivityStreamsContent(contentProp)

// Set attributedTo
attrProp := streams.NewActivityStreamsAttributedToProperty()
attrProp.AppendIRI(actorIRI)
note.SetActivityStreamsAttributedTo(attrProp)

return note
}

S2S Federation

import "github.com/go-fed/activity/pub"

// Implement required interfaces
type myActor struct{}

func (a *myActor) PostInbox(c context.Context, w http.ResponseWriter, r *http.Request) (bool, error) {
// Handle incoming activities
}

func (a *myActor) GetOutbox(c context.Context, w http.ResponseWriter, r *http.Request) (bool, error) {
// Return outbox collection
}

go-ap

Collection of ActivityPub packages.

PropertyValue
Repositorygithub.com/go-ap
LicenseMIT
StatusActive

Packages

  • go-ap/activitypub - Core types
  • go-ap/client - HTTP client
  • go-ap/handlers - HTTP handlers
  • go-ap/storage - Storage interface

Example

import (
"github.com/go-ap/activitypub"
)

note := activitypub.Note{
Type: activitypub.NoteType,
Content: activitypub.NaturalLanguageValues{{Value: "Hello!"}},
}

// Marshal to JSON
data, _ := json.Marshal(note)

httpsig

HTTP Signature library.

PropertyValue
Repositorygithub.com/go-fed/httpsig
LicenseBSD-3
StatusActive

Signing

import "github.com/go-fed/httpsig"

signer, _ := httpsig.NewSigner(
[]httpsig.Algorithm{httpsig.RSA_SHA256},
httpsig.DigestSha256,
[]string{httpsig.RequestTarget, "host", "date", "digest"},
httpsig.Signature,
0,
)

err := signer.SignRequest(privateKey, keyId, req, body)

Verification

verifier, _ := httpsig.NewVerifier(req)
pubKeyId := verifier.KeyId()

// Fetch public key using pubKeyId
err := verifier.Verify(publicKey, httpsig.RSA_SHA256)

webfinger

WebFinger client library.

PropertyValue
Repositorygithub.com/writeas/webfinger
LicenseMIT
StatusStable

Example

import "github.com/writeas/go-webfinger"

client := webfinger.NewClient(nil)

resource, err := client.Lookup("alice@example.com", nil)
if err != nil {
log.Fatal(err)
}

// Get ActivityPub actor URL
for _, link := range resource.Links {
if link.Rel == "self" &&
link.Type == "application/activity+json" {
fmt.Println(link.Href)
}
}

GoToSocial Source

Study the GoToSocial codebase for production patterns.

PropertyValue
Repositorygithub.com/superseriousbusiness/gotosocial
Key Pathsinternal/ap/, internal/federation/

Notable Patterns

  • Clean separation of concerns
  • Comprehensive test coverage
  • Good documentation

Comparison

LibraryScopeComplexityUse Case
go-fed/activityFullHighProduction servers
go-apModularMediumCustom implementations
httpsigSigning onlyLowAny project

Quick Start

For full servers: Use go-fed/activity.

For learning: Study GoToSocial source.

For custom needs: Use go-ap packages.

See Also