Replacing BaseObject with Object in the inheritance chain

This commit is contained in:
Marius Orcsik 2017-09-16 20:20:33 +02:00
parent 92e612676a
commit 7806d1c2de
No known key found for this signature in database
GPG key ID: C36D1EBE93A6EEAE
2 changed files with 21 additions and 8 deletions

View file

@ -1,9 +1,11 @@
package activitypub
var validCollectionTypes = [...]string{}
type Page ObjectOrLink
type Collection struct {
*BaseObject
*Object
// A non-negative integer specifying the total number of objects contained by the logical view of the collection.
// This number might not reflect the actual number of items serialized within the Collection object instance.
TotalItems uint `jsonld:"totalItems"`
@ -12,7 +14,7 @@ type Collection struct {
}
type OrderedCollection struct {
*BaseObject
*Object
// A non-negative integer specifying the total number of objects contained by the logical view of the collection.
// This number might not reflect the actual number of items serialized within the Collection object instance.
TotalItems uint `jsonld:"totalItems"`
@ -50,16 +52,25 @@ type OrderedCollectionPage struct {
StartIndex uint `jsonld:"startIndex"`
}
func CollectionNew(id ObjectId) *Collection {
o := BaseObject{Id: id, Type: CollectionType}
func ValidCollectionType(_type string) bool {
for _, v := range validCollectionTypes {
if v == _type {
return true
}
}
return false
}
return &Collection{BaseObject: &o}
func CollectionNew(id ObjectId) *Collection {
o := ObjectNew(id, CollectionType)
return &Collection{Object: o}
}
func OrderedCollectionNew(id ObjectId) *OrderedCollection {
o := BaseObject{Id: id, Type: OrderedCollectionType}
o := ObjectNew(id, OrderedCollectionType)
return &OrderedCollection{BaseObject: &o}
return &OrderedCollection{Object: o}
}
func CollectionPageNew(parent *Collection) *CollectionPage {

View file

@ -41,6 +41,8 @@ var validGenericTypes = [...]string{
ObjectType,
LinkType,
ActorType,
CollectionType,
OrderedCollectionType,
}
var validObjectTypes = [...]string{
@ -186,7 +188,7 @@ func ValidObjectType(_type string) bool {
return true
}
}
return ValidActivityType(_type) || ValidActorType(_type) || ValidGenericType(_type)
return ValidActivityType(_type) || ValidActorType(_type) || ValidCollectionType(_type) || ValidGenericType(_type)
}
func ObjectNew(id ObjectId, _type string) *Object {