Skip to content
ActivityStreams 2.0 encoding/decoding for Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore initial commit Jun 23, 2019
LICENSE AGPL Jun 23, 2019
README.md README Jun 23, 2019
asvocab_base_types.go initial commit Jun 23, 2019
asvocab_ext_types.go initial commit Jun 23, 2019
asvocab_interface.go initial commit Jun 23, 2019
asvocab_serialization.go initial commit Jun 23, 2019
asvocab_serialization_marshal_test.go initial commit Jun 23, 2019
asvocab_serialization_unmarshal_test.go initial commit Jun 23, 2019
asvocab_type_decoder.go
asvocab_type_encoder.go initial commit Jun 23, 2019
go.mod

README.md

astreams

License: AGPL v3

A hand-crafted implementation of the Activity Streams 2.0 specification in Go, especially suitable for projects implementing ActivityPub.

Usage

Documentation

Example Activity Streams object:

object := `
{
  "@context": "https://www.w3.org/ns/activitystreams",
  "summary": "Martin's recent activities",
  "type": "Collection",
  "totalItems": 1,
  "items" : [
    {
      "type": "Add",
      "published": "2011-02-10T15:04:55Z",
      "generator": "http://example.org/activities-app",
      "nameMap": {
        "en": "Martin added a new image to his album.",
        "ga": "Martin phost le fisean nua a albam."
      },
      "actor": {
        "type": "Person",
        "id": "http://www.test.example/martin",
        "name": "Martin Smith",
        "url": "http://example.org/martin",
        "image": {
          "type": "Link",
          "href": "http://example.org/martin/image",
          "mediaType": "image/jpeg",
          "width": 250,
          "height": 250
        }
      },
      "object" : {
        "name": "My fluffy cat",
        "type": "Image",
        "id": "http://example.org/album/máiréad.jpg",
        "preview": {
          "type": "Link",
          "href": "http://example.org/album/máiréad.jpg",
          "mediaType": "image/jpeg"
        },
        "url": [
          {
            "type": "Link",
            "href": "http://example.org/album/máiréad.jpg",
            "mediaType": "image/jpeg"
          },
          {
            "type": "Link",
            "href": "http://example.org/album/máiréad.png",
            "mediaType": "image/png"
          }
        ]
      },
      "target": {
        "type": "Collection",
        "id": "http://example.org/album/",
        "nameMap": {
          "en": "Martin's Photo Album",
          "ga": "Grianghraif Mairtin"
        },
        "image": {
          "type": "Link",
          "href": "http://example.org/album/thumbnail.jpg",
          "mediaType": "image/jpeg"
        }
      }
    }
  ]
}
`

Unmarshaling Activity Streams 2.0 JSON objects into Go objects:

// Unmarshal from AS 2.0 JSON
var exobj astreams.Collection
err := json.Unmarshal([]byte(object), &exobj)
if err != nil {
	log.Println(err)
}

↑ An example of unmarshaling into an astreams.Collection object.

Marshaling Go objects into Activity Streams 2.0 JSON objects:

// Marshal to AS 2.0 JSON
jsB, err := json.Marshal(exobj)
if err != nil {
	log.Println(err)
}

↑ Marshaling the same astreams.Collection back into the original ActivityStreams 2.0 JSON is equally as straightforward.

Contributing

Contributions are welcome. If you've found a bug, or have a feature request, don't hesitate to open an issue.

You can’t perform that action at this time.