This repository has been archived on 2022-11-27. You can view files and clone it, but cannot push or open issues or pull requests.
activitypub/unmarshall.go

31 lines
778 B
Go
Raw Normal View History

package activitypub
import (
2019-08-01 11:40:43 +00:00
"github.com/buger/jsonparser"
as "github.com/go-ap/activitystreams"
)
func JSONGetItemByType(typ as.ActivityVocabularyType) (as.Item, error) {
obTyp := as.ActivityVocabularyTypes{as.ObjectType}
if as.ObjectTypes.Contains(typ) || obTyp.Contains(typ) {
return &Object{Parent: as.Object{Type: typ}}, nil
2019-09-09 18:21:14 +00:00
}
actTyp := as.ActivityVocabularyTypes{as.ActorType}
if as.ActorTypes.Contains(typ) || actTyp.Contains(typ) {
return &actor{Parent: Parent{Parent: as.Object{Type: typ}}}, nil
}
2019-09-09 18:21:14 +00:00
return as.JSONGetItemByType(typ)
}
2019-08-01 11:40:43 +00:00
func JSONGetActorEndpoints(data []byte, prop string) *Endpoints {
str, _ := jsonparser.GetUnsafeString(data, prop)
var e *Endpoints
if len(str) > 0 {
e = &Endpoints{}
e.UnmarshalJSON([]byte(str))
}
return e
}