Files
web-core-fr-gp/activitystreams/data.go
T

76 lines
1.8 KiB
Go
Raw Normal View History

2018-06-22 16:42:38 -04:00
package activitystreams
2018-06-24 21:06:26 -04:00
import "fmt"
2018-06-22 16:42:38 -04:00
type (
2018-06-22 17:11:07 -04:00
BaseObject struct {
2018-08-03 00:21:06 +02:00
Context []interface{} `json:"@context,omitempty"`
Type string `json:"type"`
ID string `json:"id"`
2018-06-22 17:11:07 -04:00
}
2018-06-22 16:42:38 -04:00
PublicKey struct {
ID string `json:"id"`
Owner string `json:"owner"`
PublicKeyPEM string `json:"publicKeyPem"`
2018-06-25 11:32:12 -04:00
privateKey []byte
2018-06-22 16:42:38 -04:00
}
2018-08-03 00:22:42 +02:00
Endpoints struct {
SharedInbox string `json:"sharedInbox"`
}
2018-06-22 16:42:38 -04:00
Image struct {
Type string `json:"type"`
MediaType string `json:"mediaType"`
URL string `json:"url"`
}
)
2018-06-22 17:11:07 -04:00
type OrderedCollection struct {
BaseObject
TotalItems int `json:"totalItems"`
First string `json:"first"`
Last string `json:"last,omitempty"`
}
func NewOrderedCollection(accountRoot, collType string, items int) *OrderedCollection {
2018-06-22 17:11:07 -04:00
oc := OrderedCollection{
BaseObject: BaseObject{
2018-08-03 00:21:06 +02:00
Context: []interface{}{
2018-08-04 14:23:14 +02:00
Namespace,
2018-06-22 17:11:07 -04:00
},
ID: accountRoot + "/" + collType,
2018-06-22 17:11:07 -04:00
Type: "OrderedCollection",
},
First: accountRoot + "/" + collType + "?page=1",
2018-06-22 17:11:07 -04:00
TotalItems: items,
}
return &oc
}
2018-06-24 21:06:26 -04:00
type OrderedCollectionPage struct {
BaseObject
TotalItems int `json:"totalItems"`
PartOf string `json:"partOf"`
Next string `json:"next,omitempty"`
Prev string `json:"prev,omitempty"`
OrderedItems []interface{} `json:"orderedItems,omitempty"`
2018-06-24 21:06:26 -04:00
}
func NewOrderedCollectionPage(accountRoot, collType string, items, page int) *OrderedCollectionPage {
2018-06-24 21:06:26 -04:00
ocp := OrderedCollectionPage{
BaseObject: BaseObject{
2018-08-03 00:21:06 +02:00
Context: []interface{}{
2018-08-04 14:23:14 +02:00
Namespace,
2018-06-24 21:06:26 -04:00
},
ID: fmt.Sprintf("%s/%s?page=%d", accountRoot, collType, page),
2018-06-24 21:06:26 -04:00
Type: "OrderedCollectionPage",
},
TotalItems: items,
PartOf: accountRoot + "/" + collType,
Next: fmt.Sprintf("%s/%s?page=%d", accountRoot, collType, page+1),
2018-06-24 21:06:26 -04:00
}
return &ocp
}