Golint suggestions
This commit is contained in:
parent
d43c1e752f
commit
05c44839f3
|
@ -227,147 +227,203 @@ type Question struct {
|
||||||
Closed bool `jsonld:"closed,omitempty"`
|
Closed bool `jsonld:"closed,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AcceptNew initializes an Accept activity
|
||||||
func AcceptNew(id ObjectId, ob ObjectOrLink) *Accept {
|
func AcceptNew(id ObjectId, ob ObjectOrLink) *Accept {
|
||||||
a := ActivityNew(id, AcceptType, ob)
|
a := ActivityNew(id, AcceptType, ob)
|
||||||
o := Accept(*a)
|
o := Accept(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddNew initializes an Add activity
|
||||||
func AddNew(id ObjectId, ob ObjectOrLink) *Add {
|
func AddNew(id ObjectId, ob ObjectOrLink) *Add {
|
||||||
a := ActivityNew(id, AddType, ob)
|
a := ActivityNew(id, AddType, ob)
|
||||||
o := Add(*a)
|
o := Add(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AnnounceNew initializes an Announce activity
|
||||||
func AnnounceNew(id ObjectId, ob ObjectOrLink) *Announce {
|
func AnnounceNew(id ObjectId, ob ObjectOrLink) *Announce {
|
||||||
a := ActivityNew(id, AnnounceType, ob)
|
a := ActivityNew(id, AnnounceType, ob)
|
||||||
o := Announce(*a)
|
o := Announce(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArriveNew initializes an Arrive activity
|
||||||
func ArriveNew(id ObjectId) *Arrive {
|
func ArriveNew(id ObjectId) *Arrive {
|
||||||
a := IntransitiveActivityNew(id, ArriveType)
|
a := IntransitiveActivityNew(id, ArriveType)
|
||||||
o := Arrive(*a)
|
o := Arrive(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BlockNew initializes a Block activity
|
||||||
func BlockNew(id ObjectId, ob ObjectOrLink) *Block {
|
func BlockNew(id ObjectId, ob ObjectOrLink) *Block {
|
||||||
a := ActivityNew(id, BlockType, ob)
|
a := ActivityNew(id, BlockType, ob)
|
||||||
o := Block(*a)
|
o := Block(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateNew initializes a Create activity
|
||||||
func CreateNew(id ObjectId, ob ObjectOrLink) *Create {
|
func CreateNew(id ObjectId, ob ObjectOrLink) *Create {
|
||||||
a := ActivityNew(id, CreateType, ob)
|
a := ActivityNew(id, CreateType, ob)
|
||||||
o := Create(*a)
|
o := Create(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteNew initializes a Delete activity
|
||||||
func DeleteNew(id ObjectId, ob ObjectOrLink) *Delete {
|
func DeleteNew(id ObjectId, ob ObjectOrLink) *Delete {
|
||||||
a := ActivityNew(id, DeleteType, ob)
|
a := ActivityNew(id, DeleteType, ob)
|
||||||
o := Delete(*a)
|
o := Delete(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DislikeNew initializes a Dislike activity
|
||||||
func DislikeNew(id ObjectId, ob ObjectOrLink) *Dislike {
|
func DislikeNew(id ObjectId, ob ObjectOrLink) *Dislike {
|
||||||
a := ActivityNew(id, DislikeType, ob)
|
a := ActivityNew(id, DislikeType, ob)
|
||||||
o := Dislike(*a)
|
o := Dislike(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FlagNew initializes a Flag activity
|
||||||
func FlagNew(id ObjectId, ob ObjectOrLink) *Flag {
|
func FlagNew(id ObjectId, ob ObjectOrLink) *Flag {
|
||||||
a := ActivityNew(id, FlagType, ob)
|
a := ActivityNew(id, FlagType, ob)
|
||||||
o := Flag(*a)
|
o := Flag(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FollowNew initializes a Follow activity
|
||||||
func FollowNew(id ObjectId, ob ObjectOrLink) *Follow {
|
func FollowNew(id ObjectId, ob ObjectOrLink) *Follow {
|
||||||
a := ActivityNew(id, FollowType, ob)
|
a := ActivityNew(id, FollowType, ob)
|
||||||
o := Follow(*a)
|
o := Follow(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IgnoreNew initializes an Ignore activity
|
||||||
func IgnoreNew(id ObjectId, ob ObjectOrLink) *Ignore {
|
func IgnoreNew(id ObjectId, ob ObjectOrLink) *Ignore {
|
||||||
a := ActivityNew(id, IgnoreType, ob)
|
a := ActivityNew(id, IgnoreType, ob)
|
||||||
o := Ignore(*a)
|
o := Ignore(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InviteNew initializes an Invite activity
|
||||||
func InviteNew(id ObjectId, ob ObjectOrLink) *Invite {
|
func InviteNew(id ObjectId, ob ObjectOrLink) *Invite {
|
||||||
a := ActivityNew(id, InviteType, ob)
|
a := ActivityNew(id, InviteType, ob)
|
||||||
o := Invite(*a)
|
o := Invite(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JoinNew initializes a Join activity
|
||||||
func JoinNew(id ObjectId, ob ObjectOrLink) *Join {
|
func JoinNew(id ObjectId, ob ObjectOrLink) *Join {
|
||||||
a := ActivityNew(id, JoinType, ob)
|
a := ActivityNew(id, JoinType, ob)
|
||||||
o := Join(*a)
|
o := Join(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LeaveNew initializes a Leave activity
|
||||||
func LeaveNew(id ObjectId, ob ObjectOrLink) *Leave {
|
func LeaveNew(id ObjectId, ob ObjectOrLink) *Leave {
|
||||||
a := ActivityNew(id, LeaveType, ob)
|
a := ActivityNew(id, LeaveType, ob)
|
||||||
o := Leave(*a)
|
o := Leave(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LikeNew initializes a Like activity
|
||||||
func LikeNew(id ObjectId, ob ObjectOrLink) *Like {
|
func LikeNew(id ObjectId, ob ObjectOrLink) *Like {
|
||||||
a := ActivityNew(id, LikeType, ob)
|
a := ActivityNew(id, LikeType, ob)
|
||||||
o := Like(*a)
|
o := Like(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListenNew initializes a Listen activity
|
||||||
func ListenNew(id ObjectId, ob ObjectOrLink) *Listen {
|
func ListenNew(id ObjectId, ob ObjectOrLink) *Listen {
|
||||||
a := ActivityNew(id, ListenType, ob)
|
a := ActivityNew(id, ListenType, ob)
|
||||||
o := Listen(*a)
|
o := Listen(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MoveNew initializes a Move activity
|
||||||
func MoveNew(id ObjectId, ob ObjectOrLink) *Move {
|
func MoveNew(id ObjectId, ob ObjectOrLink) *Move {
|
||||||
a := ActivityNew(id, MoveType, ob)
|
a := ActivityNew(id, MoveType, ob)
|
||||||
o := Move(*a)
|
o := Move(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OfferNew initializes an Offer activity
|
||||||
func OfferNew(id ObjectId, ob ObjectOrLink) *Offer {
|
func OfferNew(id ObjectId, ob ObjectOrLink) *Offer {
|
||||||
a := ActivityNew(id, OfferType, ob)
|
a := ActivityNew(id, OfferType, ob)
|
||||||
o := Offer(*a)
|
o := Offer(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RejectNew initializes a Reject activity
|
||||||
func RejectNew(id ObjectId, ob ObjectOrLink) *Reject {
|
func RejectNew(id ObjectId, ob ObjectOrLink) *Reject {
|
||||||
a := ActivityNew(id, RejectType, ob)
|
a := ActivityNew(id, RejectType, ob)
|
||||||
o := Reject(*a)
|
o := Reject(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadNew initializes a Read activity
|
||||||
func ReadNew(id ObjectId, ob ObjectOrLink) *Read {
|
func ReadNew(id ObjectId, ob ObjectOrLink) *Read {
|
||||||
a := ActivityNew(id, ReadType, ob)
|
a := ActivityNew(id, ReadType, ob)
|
||||||
o := Read(*a)
|
o := Read(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveNew initializes a Remove activity
|
||||||
func RemoveNew(id ObjectId, ob ObjectOrLink) *Remove {
|
func RemoveNew(id ObjectId, ob ObjectOrLink) *Remove {
|
||||||
a := ActivityNew(id, RemoveType, ob)
|
a := ActivityNew(id, RemoveType, ob)
|
||||||
o := Remove(*a)
|
o := Remove(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TentativeRejectNew initializes a TentativeReject activity
|
||||||
func TentativeRejectNew(id ObjectId, ob ObjectOrLink) *TentativeReject {
|
func TentativeRejectNew(id ObjectId, ob ObjectOrLink) *TentativeReject {
|
||||||
a := ActivityNew(id, TentativeRejectType, ob)
|
a := ActivityNew(id, TentativeRejectType, ob)
|
||||||
o := TentativeReject(*a)
|
o := TentativeReject(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TentativeAcceptNew initializes a TentativeAccept activity
|
||||||
func TentativeAcceptNew(id ObjectId, ob ObjectOrLink) *TentativeAccept {
|
func TentativeAcceptNew(id ObjectId, ob ObjectOrLink) *TentativeAccept {
|
||||||
a := ActivityNew(id, TentativeAcceptType, ob)
|
a := ActivityNew(id, TentativeAcceptType, ob)
|
||||||
o := TentativeAccept(*a)
|
o := TentativeAccept(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TravelNew initializes a Travel activity
|
||||||
func TravelNew(id ObjectId) *Travel {
|
func TravelNew(id ObjectId) *Travel {
|
||||||
a := IntransitiveActivityNew(id, TravelType)
|
a := IntransitiveActivityNew(id, TravelType)
|
||||||
o := Travel(*a)
|
o := Travel(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UndoNew initializes an Undo activity
|
||||||
func UndoNew(id ObjectId, ob ObjectOrLink) *Undo {
|
func UndoNew(id ObjectId, ob ObjectOrLink) *Undo {
|
||||||
a := ActivityNew(id, UndoType, ob)
|
a := ActivityNew(id, UndoType, ob)
|
||||||
o := Undo(*a)
|
o := Undo(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateNew initializes an Update activity
|
||||||
func UpdateNew(id ObjectId, ob ObjectOrLink) *Accept {
|
func UpdateNew(id ObjectId, ob ObjectOrLink) *Accept {
|
||||||
a := ActivityNew(id, UpdateType, ob)
|
a := ActivityNew(id, UpdateType, ob)
|
||||||
o := Accept(*a)
|
o := Accept(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ViewNew initializes a View activity
|
||||||
func ViewNew(id ObjectId, ob ObjectOrLink) *View {
|
func ViewNew(id ObjectId, ob ObjectOrLink) *View {
|
||||||
a := ActivityNew(id, ViewType, ob)
|
a := ActivityNew(id, ViewType, ob)
|
||||||
o := View(*a)
|
o := View(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QuestionNew initializes a Question activity
|
||||||
func QuestionNew(id ObjectId) *Question {
|
func QuestionNew(id ObjectId) *Question {
|
||||||
a := IntransitiveActivityNew(id, QuestionType)
|
a := IntransitiveActivityNew(id, QuestionType)
|
||||||
o := Question{IntransitiveActivity: a}
|
o := Question{IntransitiveActivity: a}
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidActivityType is a validation function for Activity objects
|
||||||
func ValidActivityType(_type ActivityVocabularyType) bool {
|
func ValidActivityType(_type ActivityVocabularyType) bool {
|
||||||
for _, v := range validActivityTypes {
|
for _, v := range validActivityTypes {
|
||||||
if v == _type {
|
if v == _type {
|
||||||
|
@ -377,6 +433,7 @@ func ValidActivityType(_type ActivityVocabularyType) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ActivityNew initializes a basic activity
|
||||||
func ActivityNew(id ObjectId, _type ActivityVocabularyType, ob ObjectOrLink) *Activity {
|
func ActivityNew(id ObjectId, _type ActivityVocabularyType, ob ObjectOrLink) *Activity {
|
||||||
if !ValidActivityType(_type) {
|
if !ValidActivityType(_type) {
|
||||||
_type = ActivityType
|
_type = ActivityType
|
||||||
|
@ -390,6 +447,7 @@ func ActivityNew(id ObjectId, _type ActivityVocabularyType, ob ObjectOrLink) *Ac
|
||||||
return &a
|
return &a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IntransitiveActivityNew initializes a intransitive activity
|
||||||
func IntransitiveActivityNew(id ObjectId, _type ActivityVocabularyType) *IntransitiveActivity {
|
func IntransitiveActivityNew(id ObjectId, _type ActivityVocabularyType) *IntransitiveActivity {
|
||||||
if !ValidActivityType(_type) {
|
if !ValidActivityType(_type) {
|
||||||
_type = IntransitiveActivityType
|
_type = IntransitiveActivityType
|
||||||
|
|
|
@ -87,6 +87,7 @@ type (
|
||||||
Service Actor
|
Service Actor
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ValidActorType validates the passed type against the valid actor types
|
||||||
func ValidActorType(_type ActivityVocabularyType) bool {
|
func ValidActorType(_type ActivityVocabularyType) bool {
|
||||||
for _, v := range validActorTypes {
|
for _, v := range validActorTypes {
|
||||||
if v == _type {
|
if v == _type {
|
||||||
|
@ -96,6 +97,7 @@ func ValidActorType(_type ActivityVocabularyType) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ActorNew initializes an Actor type actor
|
||||||
func ActorNew(id ObjectId, _type ActivityVocabularyType) *Actor {
|
func ActorNew(id ObjectId, _type ActivityVocabularyType) *Actor {
|
||||||
if !ValidActorType(_type) {
|
if !ValidActorType(_type) {
|
||||||
_type = ActorType
|
_type = ActorType
|
||||||
|
@ -106,30 +108,35 @@ func ActorNew(id ObjectId, _type ActivityVocabularyType) *Actor {
|
||||||
return &a
|
return &a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApplicationNew initializes an Application type actor
|
||||||
func ApplicationNew(id ObjectId) *Application {
|
func ApplicationNew(id ObjectId) *Application {
|
||||||
a := ActorNew(id, ApplicationType)
|
a := ActorNew(id, ApplicationType)
|
||||||
o := Application(*a)
|
o := Application(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GroupNew initializes a Group type actor
|
||||||
func GroupNew(id ObjectId) *Group {
|
func GroupNew(id ObjectId) *Group {
|
||||||
a := ActorNew(id, GroupType)
|
a := ActorNew(id, GroupType)
|
||||||
o := Group(*a)
|
o := Group(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OrganizationNew initializes an Organization type actor
|
||||||
func OrganizationNew(id ObjectId) *Organization {
|
func OrganizationNew(id ObjectId) *Organization {
|
||||||
a := ActorNew(id, OrganizationType)
|
a := ActorNew(id, OrganizationType)
|
||||||
o := Organization(*a)
|
o := Organization(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PersonNew initializes a Person type actor
|
||||||
func PersonNew(id ObjectId) *Person {
|
func PersonNew(id ObjectId) *Person {
|
||||||
a := ActorNew(id, PersonType)
|
a := ActorNew(id, PersonType)
|
||||||
o := Person(*a)
|
o := Person(*a)
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServiceNew initializes a Service type actor
|
||||||
func ServiceNew(id ObjectId) *Service {
|
func ServiceNew(id ObjectId) *Service {
|
||||||
a := ActorNew(id, ServiceType)
|
a := ActorNew(id, ServiceType)
|
||||||
o := Service(*a)
|
o := Service(*a)
|
||||||
|
|
|
@ -2,8 +2,10 @@ package activitypub
|
||||||
|
|
||||||
var validCollectionTypes = [...]ActivityVocabularyType{CollectionType, OrderedCollectionType}
|
var validCollectionTypes = [...]ActivityVocabularyType{CollectionType, OrderedCollectionType}
|
||||||
|
|
||||||
|
// Page
|
||||||
type Page ObjectOrLink
|
type Page ObjectOrLink
|
||||||
|
|
||||||
|
// Collection
|
||||||
type Collection struct {
|
type Collection struct {
|
||||||
*APObject
|
*APObject
|
||||||
// A non-negative integer specifying the total number of objects contained by the logical view of the collection.
|
// A non-negative integer specifying the total number of objects contained by the logical view of the collection.
|
||||||
|
@ -13,6 +15,7 @@ type Collection struct {
|
||||||
Items ItemCollection `jsonld:"items,omitempty"`
|
Items ItemCollection `jsonld:"items,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OrderedCollection
|
||||||
type OrderedCollection struct {
|
type OrderedCollection struct {
|
||||||
*APObject
|
*APObject
|
||||||
// A non-negative integer specifying the total number of objects contained by the logical view of the collection.
|
// A non-negative integer specifying the total number of objects contained by the logical view of the collection.
|
||||||
|
@ -22,6 +25,7 @@ type OrderedCollection struct {
|
||||||
OrderedItems ItemCollection `jsonld:"orderedItems,omitempty"`
|
OrderedItems ItemCollection `jsonld:"orderedItems,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CollectionPage
|
||||||
type CollectionPage struct {
|
type CollectionPage struct {
|
||||||
PartOf *Collection
|
PartOf *Collection
|
||||||
// In a paged Collection, indicates the page that contains the most recently updated member items.
|
// In a paged Collection, indicates the page that contains the most recently updated member items.
|
||||||
|
@ -36,6 +40,7 @@ type CollectionPage struct {
|
||||||
Prev Page `jsonld:"prev,omitempty"`
|
Prev Page `jsonld:"prev,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OrderedCollectionPage
|
||||||
type OrderedCollectionPage struct {
|
type OrderedCollectionPage struct {
|
||||||
PartOf *OrderedCollection
|
PartOf *OrderedCollection
|
||||||
// In a paged Collection, indicates the page that contains the most recently updated member items.
|
// In a paged Collection, indicates the page that contains the most recently updated member items.
|
||||||
|
@ -52,6 +57,7 @@ type OrderedCollectionPage struct {
|
||||||
StartIndex uint `jsonld:"startIndex,omitempty"`
|
StartIndex uint `jsonld:"startIndex,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidCollectionType validates against the valid collection types
|
||||||
func ValidCollectionType(_type ActivityVocabularyType) bool {
|
func ValidCollectionType(_type ActivityVocabularyType) bool {
|
||||||
for _, v := range validCollectionTypes {
|
for _, v := range validCollectionTypes {
|
||||||
if v == _type {
|
if v == _type {
|
||||||
|
@ -61,22 +67,26 @@ func ValidCollectionType(_type ActivityVocabularyType) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CollectionNew initializes a new Collection
|
||||||
func CollectionNew(id ObjectId) *Collection {
|
func CollectionNew(id ObjectId) *Collection {
|
||||||
o := ObjectNew(id, CollectionType)
|
o := ObjectNew(id, CollectionType)
|
||||||
|
|
||||||
return &Collection{APObject: o}
|
return &Collection{APObject: o}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CollectionNew initializes a new Collection
|
||||||
func OrderedCollectionNew(id ObjectId) *OrderedCollection {
|
func OrderedCollectionNew(id ObjectId) *OrderedCollection {
|
||||||
o := ObjectNew(id, OrderedCollectionType)
|
o := ObjectNew(id, OrderedCollectionType)
|
||||||
|
|
||||||
return &OrderedCollection{APObject: o}
|
return &OrderedCollection{APObject: o}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CollectionNew initializes a new Collection
|
||||||
func CollectionPageNew(parent *Collection) *CollectionPage {
|
func CollectionPageNew(parent *Collection) *CollectionPage {
|
||||||
return &CollectionPage{PartOf: parent}
|
return &CollectionPage{PartOf: parent}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CollectionNew initializes a new Collection
|
||||||
func OrderedCollectionPageNew(parent *OrderedCollection) *OrderedCollectionPage {
|
func OrderedCollectionPageNew(parent *OrderedCollection) *OrderedCollectionPage {
|
||||||
return &OrderedCollectionPage{PartOf: parent}
|
return &OrderedCollectionPage{PartOf: parent}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package activitypub
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
// CreateActivity is the type for a create activity message
|
||||||
type CreateActivity struct {
|
type CreateActivity struct {
|
||||||
Activity *Create
|
Activity *Create
|
||||||
Published time.Time
|
Published time.Time
|
||||||
|
@ -9,6 +10,7 @@ type CreateActivity struct {
|
||||||
CC *Actor
|
CC *Actor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateActivityNew initializes a new CreateActivity message
|
||||||
func CreateActivityNew(id ObjectId, o ObjectOrLink) *CreateActivity {
|
func CreateActivityNew(id ObjectId, o ObjectOrLink) *CreateActivity {
|
||||||
c := CreateActivity{
|
c := CreateActivity{
|
||||||
Activity: CreateNew(id, o),
|
Activity: CreateNew(id, o),
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package activitypub
|
package activitypub
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// FollowersCollection is a collection of followers
|
||||||
FollowersCollection Followers
|
FollowersCollection Followers
|
||||||
|
|
||||||
|
// Followers is a Collection type
|
||||||
Followers Collection
|
Followers Collection
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package activitypub
|
package activitypub
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// FollowingCollection
|
||||||
FollowingCollection Following
|
FollowingCollection Following
|
||||||
|
|
||||||
|
// Following
|
||||||
Following Collection
|
Following Collection
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package activitypub
|
package activitypub
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// InboxStream
|
||||||
InboxStream Inbox
|
InboxStream Inbox
|
||||||
|
|
||||||
|
// Inbox
|
||||||
Inbox OrderedCollection
|
Inbox OrderedCollection
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package activitypub
|
package activitypub
|
||||||
|
|
||||||
|
// ItemCollection is an array of items
|
||||||
type ItemCollection []Item
|
type ItemCollection []Item
|
||||||
|
|
||||||
type Item struct {
|
// Item struct
|
||||||
}
|
type Item struct{}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package activitypub
|
package activitypub
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// LikedCollection
|
||||||
LikedCollection Liked
|
LikedCollection Liked
|
||||||
|
|
||||||
|
// Liked
|
||||||
Liked OrderedCollection
|
Liked OrderedCollection
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package activitypub
|
package activitypub
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// LikesCollection
|
||||||
LikesCollection Likes
|
LikesCollection Likes
|
||||||
|
|
||||||
|
// Likes
|
||||||
Likes OrderedCollection
|
Likes OrderedCollection
|
||||||
)
|
)
|
||||||
|
|
|
@ -40,8 +40,10 @@ type Link struct {
|
||||||
HrefLang LangRef `jsonld:"hrefLang,omitempty"`
|
HrefLang LangRef `jsonld:"hrefLang,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mention
|
||||||
type Mention Link
|
type Mention Link
|
||||||
|
|
||||||
|
// ValidLinkType validates a type against the valid link types
|
||||||
func ValidLinkType(_type ActivityVocabularyType) bool {
|
func ValidLinkType(_type ActivityVocabularyType) bool {
|
||||||
for _, v := range validLinkTypes {
|
for _, v := range validLinkTypes {
|
||||||
if v == _type {
|
if v == _type {
|
||||||
|
@ -51,6 +53,7 @@ func ValidLinkType(_type ActivityVocabularyType) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LinkNew initializes a new Link
|
||||||
func LinkNew(id ObjectId, _type ActivityVocabularyType) *Link {
|
func LinkNew(id ObjectId, _type ActivityVocabularyType) *Link {
|
||||||
if !ValidLinkType(_type) {
|
if !ValidLinkType(_type) {
|
||||||
_type = LinkType
|
_type = LinkType
|
||||||
|
@ -58,22 +61,27 @@ func LinkNew(id ObjectId, _type ActivityVocabularyType) *Link {
|
||||||
return &Link{Id: id, Type: _type}
|
return &Link{Id: id, Type: _type}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MentionNew initializes a new Mention
|
||||||
func MentionNew(id ObjectId) *Mention {
|
func MentionNew(id ObjectId) *Mention {
|
||||||
return &Mention{Id: id, Type: MentionType}
|
return &Mention{Id: id, Type: MentionType}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsLink validates if current Link is a Link
|
||||||
func (l Link) IsLink() bool {
|
func (l Link) IsLink() bool {
|
||||||
return l.Type == LinkType || ValidLinkType(l.Type)
|
return l.Type == LinkType || ValidLinkType(l.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsObject validates if current Link is an Object
|
||||||
func (l Link) IsObject() bool {
|
func (l Link) IsObject() bool {
|
||||||
return l.Type == ObjectType || ValidObjectType(l.Type)
|
return l.Type == ObjectType || ValidObjectType(l.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsLink validates if current Mention is a Link
|
||||||
func (l Mention) IsLink() bool {
|
func (l Mention) IsLink() bool {
|
||||||
return l.Type == MentionType || ValidLinkType(l.Type)
|
return l.Type == MentionType || ValidLinkType(l.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsObject validates if current Mention is an Object
|
||||||
func (l Mention) IsObject() bool {
|
func (l Mention) IsObject() bool {
|
||||||
return l.Type == ObjectType || ValidObjectType(l.Type)
|
return l.Type == ObjectType || ValidObjectType(l.Type)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ObjectId
|
||||||
type ObjectId string
|
type ObjectId string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// ActivityBaseURI the basic URI for the activity streams namespaces
|
||||||
ActivityBaseURI URI = URI("https://www.w3.org/ns/activitystreams#")
|
ActivityBaseURI URI = URI("https://www.w3.org/ns/activitystreams#")
|
||||||
ObjectType ActivityVocabularyType = "APObject"
|
ObjectType ActivityVocabularyType = "APObject"
|
||||||
LinkType ActivityVocabularyType = "Link"
|
LinkType ActivityVocabularyType = "Link"
|
||||||
|
@ -66,27 +68,38 @@ var validObjectTypes = [...]ActivityVocabularyType{
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// ActivityVocabularyType
|
||||||
ActivityVocabularyType string
|
ActivityVocabularyType string
|
||||||
ActivityObject interface{}
|
// ActivityObject
|
||||||
ObjectOrLink interface {
|
ActivityObject interface{}
|
||||||
|
// ObjectOrLink
|
||||||
|
ObjectOrLink interface {
|
||||||
IsLink() bool
|
IsLink() bool
|
||||||
IsObject() bool
|
IsObject() bool
|
||||||
}
|
}
|
||||||
LinkOrUri interface{}
|
// LinkOrUri
|
||||||
ImageOrLink interface{}
|
LinkOrUri interface{}
|
||||||
MimeType string
|
// ImageOrLink
|
||||||
LangRef string
|
ImageOrLink interface{}
|
||||||
|
// MimeType
|
||||||
|
MimeType string
|
||||||
|
// LangRef
|
||||||
|
LangRef string
|
||||||
|
// NaturalLanguageValue
|
||||||
NaturalLanguageValue map[LangRef]string
|
NaturalLanguageValue map[LangRef]string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IsLink validates if current APObject is a Link
|
||||||
func (o APObject) IsLink() bool {
|
func (o APObject) IsLink() bool {
|
||||||
return ValidLinkType(o.Type)
|
return ValidLinkType(o.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsObject validates if current APObject is an Object
|
||||||
func (o APObject) IsObject() bool {
|
func (o APObject) IsObject() bool {
|
||||||
return ValidObjectType(o.Type)
|
return ValidObjectType(o.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON serializes the NaturalLanguageValue into JSON
|
||||||
func (n NaturalLanguageValue) MarshalJSON() ([]byte, error) {
|
func (n NaturalLanguageValue) MarshalJSON() ([]byte, error) {
|
||||||
if len(n) == 1 {
|
if len(n) == 1 {
|
||||||
for _, v := range n {
|
for _, v := range n {
|
||||||
|
@ -180,13 +193,16 @@ type APObject struct {
|
||||||
Duration time.Duration `jsonld:"duration,omitempty"`
|
Duration time.Duration `jsonld:"duration,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContentType
|
||||||
type ContentType string
|
type ContentType string
|
||||||
|
|
||||||
|
// Source
|
||||||
type Source struct {
|
type Source struct {
|
||||||
Content ContentType
|
Content ContentType
|
||||||
MediaType string
|
MediaType string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidGenericType validates the type against the valid generic object types
|
||||||
func ValidGenericType(_type ActivityVocabularyType) bool {
|
func ValidGenericType(_type ActivityVocabularyType) bool {
|
||||||
for _, v := range validGenericObjectTypes {
|
for _, v := range validGenericObjectTypes {
|
||||||
if v == _type {
|
if v == _type {
|
||||||
|
@ -196,6 +212,7 @@ func ValidGenericType(_type ActivityVocabularyType) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidObjectType validates the type against the valid object types
|
||||||
func ValidObjectType(_type ActivityVocabularyType) bool {
|
func ValidObjectType(_type ActivityVocabularyType) bool {
|
||||||
for _, v := range validObjectTypes {
|
for _, v := range validObjectTypes {
|
||||||
if v == _type {
|
if v == _type {
|
||||||
|
@ -205,6 +222,7 @@ func ValidObjectType(_type ActivityVocabularyType) bool {
|
||||||
return ValidActivityType(_type) || ValidActorType(_type) || ValidCollectionType(_type) || ValidGenericType(_type)
|
return ValidActivityType(_type) || ValidActorType(_type) || ValidCollectionType(_type) || ValidGenericType(_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ObjectNew initializes a new Object
|
||||||
func ObjectNew(id ObjectId, _type ActivityVocabularyType) *APObject {
|
func ObjectNew(id ObjectId, _type ActivityVocabularyType) *APObject {
|
||||||
if !(ValidObjectType(_type)) {
|
if !(ValidObjectType(_type)) {
|
||||||
_type = ObjectType
|
_type = ObjectType
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package activitypub
|
package activitypub
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// OutboxStream
|
||||||
OutboxStream Outbox
|
OutboxStream Outbox
|
||||||
|
|
||||||
|
// Outbox
|
||||||
Outbox OrderedCollection
|
Outbox OrderedCollection
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package activitypub
|
package activitypub
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// SharesCollection
|
||||||
SharesCollection Shares
|
SharesCollection Shares
|
||||||
|
|
||||||
|
// Shares
|
||||||
Shares OrderedCollection
|
Shares OrderedCollection
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package activitypub
|
package activitypub
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// IRI
|
||||||
IRI URI
|
IRI URI
|
||||||
|
|
||||||
|
// URI
|
||||||
URI string
|
URI string
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,26 +6,32 @@ import (
|
||||||
"activitypub"
|
"activitypub"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Ref basic type
|
||||||
type Ref string
|
type Ref string
|
||||||
|
|
||||||
|
// Context is the basic JSON-LD element. It is used to map terms to IRIs.
|
||||||
|
// Terms are case sensitive and any valid string that is not a reserved JSON-LD
|
||||||
|
// keyword can be used as a term.
|
||||||
type Context struct {
|
type Context struct {
|
||||||
URL Ref `jsonld:"@url"`
|
URL Ref `jsonld:"@url"`
|
||||||
Language activitypub.NaturalLanguageValue `jsonld:"@language,omitempty,collapsible"`
|
Language activitypub.NaturalLanguageValue `jsonld:"@language,omitempty,collapsible"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ref returns a new Ref object based on Context URL
|
||||||
func (c *Context) Ref() Ref {
|
func (c *Context) Ref() Ref {
|
||||||
return Ref(c.URL)
|
return Ref(c.URL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalText basic stringify function
|
||||||
func (r *Ref) MarshalText() ([]byte, error) {
|
func (r *Ref) MarshalText() ([]byte, error) {
|
||||||
return []byte(*r), nil
|
return []byte(*r), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON returns the JSON document represented by the current Context
|
||||||
func (c *Context) MarshalJSON() ([]byte, error) {
|
func (c *Context) MarshalJSON() ([]byte, error) {
|
||||||
a := reflectToJSONValue(c)
|
a := reflectToJSONValue(c)
|
||||||
if a.isScalar {
|
if a.isScalar {
|
||||||
return json.Marshal(a.scalar)
|
return json.Marshal(a.scalar)
|
||||||
} else {
|
|
||||||
return json.Marshal(a.object)
|
|
||||||
}
|
}
|
||||||
|
return json.Marshal(a.object)
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,8 +183,6 @@ func (p *payloadWithContext) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(a.object)
|
return json.Marshal(a.object)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Encoder struct{}
|
|
||||||
|
|
||||||
type jsonLdTag struct {
|
type jsonLdTag struct {
|
||||||
name string
|
name string
|
||||||
ignore bool
|
ignore bool
|
||||||
|
|
|
@ -96,7 +96,7 @@ func TestIsEmpty(t *testing.T) {
|
||||||
if !isEmptyValue(reflect.ValueOf(d)) {
|
if !isEmptyValue(reflect.ValueOf(d)) {
|
||||||
t.Errorf("Invalid empty value %v", d)
|
t.Errorf("Invalid empty value %v", d)
|
||||||
}
|
}
|
||||||
var e *interface{} = nil
|
var e *interface{}
|
||||||
if !isEmptyValue(reflect.ValueOf(e)) {
|
if !isEmptyValue(reflect.ValueOf(e)) {
|
||||||
t.Errorf("Invalid empty value %v", e)
|
t.Errorf("Invalid empty value %v", e)
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue