Added ToPerson function

This commit is contained in:
Marius Orcsik 2019-05-15 22:22:36 +02:00
parent 8b5feb3b2b
commit c2cc81ff3b
No known key found for this signature in database
GPG key ID: 889CE8E4FB2D877A
3 changed files with 21 additions and 2 deletions

View file

@ -1,6 +1,9 @@
package activitypub
import as "github.com/go-ap/activitystreams"
import (
"errors"
as "github.com/go-ap/activitystreams"
)
// Endpoints a json object which maps additional (typically server/domain-wide)
// endpoints which may be useful either for this actor or someone referencing this actor.
@ -151,3 +154,15 @@ func (a *actor)UnmarshalJSON(data []byte) error {
//a.Streams = as.JSONGetItems(data, "streams")
return nil
}
// ToObject
func ToPerson(it as.Item) (*Person, error) {
switch i := it.(type) {
case *actor:
return i, nil
case actor:
return &i, nil
}
return nil, errors.New("unable to convert object")
}

View file

@ -333,3 +333,7 @@ func TestService_IsLink(t *testing.T) {
func TestService_IsObject(t *testing.T) {
t.Skipf("TODO")
}
func TestToPerson(t *testing.T) {
t.Skipf("TODO")
}

2
go.mod
View file

@ -2,6 +2,6 @@ module github.com/go-ap/activitypub
require (
github.com/buger/jsonparser v0.0.0-20181023193515-52c6e1462ebd
github.com/go-ap/activitystreams v0.0.0-20190306111705-2a794fbd6a34
github.com/go-ap/activitystreams v0.0.0-20190512181306-9255f5ce5de3
github.com/go-ap/jsonld v0.0.0-20190306111347-fbb94302fe92
)