Migrate pub to go-fed.

このコミットが含まれているのは:
Cory Slep 2018-01-26 00:19:21 +01:00
コミット 9300d8583e
11個のファイルの変更2623行の追加2132行の削除

240
pub/fed.go ノーマルファイル
ファイルの表示

@ -0,0 +1,240 @@
package pub
import (
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/vocab"
"net/http"
"net/url"
)
// Object is the interface for ActivityPub compliant ActivityStream types.
//
// ActivityPub obects must have 'id' and 'type' properties to be spec compliant.
// This library enforces the "MUST" requirement and purposefully does NOT
// support transient objects.
//
// Furthermore, the spec extends the Object ActivityStream type to also contain
// the 'source' property, whose value appears to be an Object with only
// 'content' and 'mediaType' properties being semantically useful.
type Object interface {
GetId() (streams.Resolution, url.URL)
SetId(url.URL)
HasId() streams.Presence
LenType() int
GetType(int) (streams.Resolution, string)
AddType(interface{})
RemoveType(int)
ResolveSource(*streams.Resolver) (streams.Resolution, error)
HasSource() streams.Presence
SetSource(vocab.ObjectType)
Serialize() (m map[string]interface{}, err error)
}
var _ Object = &streams.Object{}
// Actor is the interface for ActivityPub compliant ActivityStream types.
//
// ActivityPub actors must have a valid unique IRI as the 'id' property in
// addition to the 'type' property. Furthermore, actors must have the 'inbox'
// and 'outbox' properties to be considered actors. There are more suggested
// properties by the spec, which we include here.
type Actor interface {
GetId() (streams.Resolution, url.URL)
SetId(url.URL)
LenType() int
GetType(int) (streams.Resolution, string)
AddType(interface{})
RemoveType(int)
GetInbox() (streams.Resolution, url.URL)
HasInbox() streams.Presence
SetInbox(url.URL)
GetOutbox() (streams.Resolution, url.URL)
HasOutbox() streams.Presence
SetOutbox(url.URL)
GetFollowing() (streams.Resolution, url.URL)
HasFollowing() streams.Presence
SetFollowing(url.URL)
GetFollowers() (streams.Resolution, url.URL)
HasFollowers() streams.Presence
SetFollowers(url.URL)
GetLiked() (streams.Resolution, url.URL)
HasLiked() streams.Presence
SetLiked(url.URL)
LenStreams() int
GetStreams(int) (streams.Resolution, url.URL)
AddStreams(vocab.CollectionType)
RemoveStreams(int)
GetPreferredUsername() (streams.Resolution, string)
HasPreferredUsername() streams.Presence
SetPreferredUsername(string)
PreferredUsernameLanguages() []string
GetPreferredUsernameForLanguage(string) string
SetPreferredUsernameForLanguage(string, string)
ResolveEndpoints(streams.Resolver) (streams.Resolution, error)
HasEndpoints() streams.Presence
SetEndpoints(vocab.ObjectType)
Serialize() (m map[string]interface{}, err error)
}
var _ Object = &streams.Object{}
// Endpoint is a logical grouping of specific properties within the ActivityPub
// specification.
type Endpoint interface {
GetProxyUrl() (streams.Resolution, url.URL)
HasProxyUrl() streams.Presence
SetProxyUrl(url.URL)
GetOauthAuthorizationEndpoint() (streams.Resolution, url.URL)
HasOauthAuthorizationEndpoint() streams.Presence
SetOauthAuthorizationEndpoint(url.URL)
GetOauthTokenEndpoint() (streams.Resolution, url.URL)
HasOauthTokenEndpoint() streams.Presence
SetOauthTokenEndpoint(url.URL)
GetProvideClientKey() (streams.Resolution, url.URL)
HasProvideClientKey() streams.Presence
SetProvideClientKey(url.URL)
GetSignClientKey() (streams.Resolution, url.URL)
HasSignClientKey() streams.Presence
SetSignClientKey(url.URL)
GetSharedInbox() (streams.Resolution, url.URL)
HasSharedInbox() streams.Presence
SetSharedInbox(url.URL)
}
var _ Endpoint = &streams.Object{}
// Storer is a long term storage solution provided by clients so that data can
// be saved and retrieved by the ActivityPub federated server.
type Storer interface {
// TODO
}
// Server implements receiving the federated portion of the ActivityPub
// specification.
//
// It implements a single 'sharedinbox' to trade off numerous messages over the
// network for increased internal processing. Additionally, it will keep track
// of externally-known 'sharedInbox' in order to send public messages
// efficiently, as permitted by the spec.
//
// Fields that are able to be 'nil' are marked as such; otherwise assume that
// all fields are required.
type Server struct {
// S is used for long-term storage and retrieval of ActivityPub
// messages.
S Storer
}
// OnInbox proides a handler function for when an Actor receives an Activity.
func (s *Server) OnInbox() (http.HandlerFunc, error) {
// TODO: Implement
return nil, nil
}
func (s *Server) OnOutbox() (http.HandlerFunc, error) {
// TODO: Implement
return nil, nil
}
func (s *Server) OnSharedInbox() (http.HandlerFunc, error) {
// TODO: Implement
return nil, nil
}
func (s *Server) OnFollowers() (http.HandlerFunc, error) {
// TODO: Implement
return nil, nil
}
func (s *Server) OnFollowing() (http.HandlerFunc, error) {
// TODO: Implement
return nil, nil
}
func (s *Server) OnLiked() (http.HandlerFunc, error) {
// TODO: Implement
return nil, nil
}
func (s *Server) OnLikes() (http.HandlerFunc, error) {
// TODO: Implement
return nil, nil
}
func (s *Server) OnShares() (http.HandlerFunc, error) {
// TODO: Implement
return nil, nil
}
// Client implements sending the federated portion of the ActivityPub
// specification.
type Client struct {
// Client is used to federate with other ActivityPub servers.
Client *http.Client
// Agent is the User-Agent string to use in HTTP headers when
// federating with another server. It will automatically be appended
// with '(go-fed ActivityPub)'.
Agent string
// MaxDepth is how deep collections of recipients will be expanded for
// delivery. It must be at least 1 to be compliant with the ActivityPub
// spec.
MaxDepth int
}
func (c *Client) Create() error {
// TODO: Enforce object
// TODO: Implement
return nil
}
func (c *Client) Update() error {
// TODO: Enforce object
// TODO: Implement
return nil
}
func (c *Client) Delete() error {
// TODO: Enforce object
// TODO: Implement
return nil
}
func (c *Client) Follow() error {
// TODO: Enforce object
// TODO: Implement
return nil
}
func (c *Client) Accept() error {
// TODO: Implement
return nil
}
func (c *Client) Reject() error {
// TODO: Implement
return nil
}
func (c *Client) Add() error {
// TODO: Enforce object & target
// TODO: Implement
return nil
}
func (c *Client) Remove() error {
// TODO: Enforce object & target
// TODO: Implement
return nil
}
func (c *Client) Like() error {
// TODO: Enforce object
// TODO: Implement
return nil
}
func (c *Client) Undo() error {
// TODO: Enforce object
// TODO: Implement
return nil
}

59
pub/interfaces.go ノーマルファイル
ファイルの表示

@ -0,0 +1,59 @@
package pub
import (
"github.com/go-fed/activity/vocab"
"net/url"
)
// ActorObject is an object that has "actor" or "attributedTo" properties,
// representing the author or originator of the object.
type ActorObject interface {
// TODO: Populate
}
// DeliverableObject is an object that is able to be sent to recipients via the
// "to", "bto", "cc", "bcc", and "audience" objects and/or links and/or IRIs.
type DeliverableObject interface {
ActorObject
ToLen() (l int)
IsToObject(index int) (ok bool)
GetToObject(index int) (v vocab.ObjectType)
IsToLink(index int) (ok bool)
GetToLink(index int) (v vocab.LinkType)
IsToIRI(index int) (ok bool)
GetToIRI(index int) (v url.URL)
BtoLen() (l int)
IsBtoObject(index int) (ok bool)
GetBtoObject(index int) (v vocab.ObjectType)
RemoveBtoObject(index int)
IsBtoLink(index int) (ok bool)
GetBtoLink(index int) (v vocab.LinkType)
RemoveBtoLink(index int)
IsBtoIRI(index int) (ok bool)
GetBtoIRI(index int) (v url.URL)
RemoveBtoIRI(index int)
CcLen() (l int)
IsCcObject(index int) (ok bool)
GetCcObject(index int) (v vocab.ObjectType)
IsCcLink(index int) (ok bool)
GetCcLink(index int) (v vocab.LinkType)
IsCcIRI(index int) (ok bool)
GetCcIRI(index int) (v url.URL)
BccLen() (l int)
IsBccObject(index int) (ok bool)
GetBccObject(index int) (v vocab.ObjectType)
RemoveBccObject(index int)
IsBccLink(index int) (ok bool)
GetBccLink(index int) (v vocab.LinkType)
RemoveBccLink(index int)
IsBccIRI(index int) (ok bool)
GetBccIRI(index int) (v url.URL)
RemoveBccIRI(index int)
AudienceLen() (l int)
IsAudienceObject(index int) (ok bool)
GetAudienceObject(index int) (v vocab.ObjectType)
IsAudienceLink(index int) (ok bool)
GetAudienceLink(index int) (v vocab.LinkType)
IsAudienceIRI(index int) (ok bool)
GetAudienceIRI(index int) (v url.URL)
}

485
pub/internal.go ノーマルファイル
ファイルの表示

@ -0,0 +1,485 @@
package pub
import (
"encoding/json"
"fmt"
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/vocab"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"
)
const (
postContentTypeHeader = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
getAcceptHeader = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
contentTypeHeader = "Content-Type"
acceptHeader = "Accept"
publicActivityPub = "https://www.w3.org/ns/activitystreams#Public"
publicJsonLD = "Public"
publicJsonLDAS = "as:Public"
)
var alternatives = []string{"application/activity+json"}
func trimAll(s []string) []string {
var r []string
for _, e := range s {
r = append(r, strings.Trim(e, " "))
}
return r
}
func headerEqualsOneOf(header string, acceptable []string) bool {
sanitizedHeader := strings.Join(trimAll(strings.Split(header, ";")), ";")
for _, v := range acceptable {
// Remove any number of whitespace after ;'s
sanitizedV := strings.Join(trimAll(strings.Split(v, ";")), ";")
if sanitizedHeader == sanitizedV {
return true
}
}
return false
}
func isActivityPubPost(r *http.Request) bool {
return r.Method == "POST" && headerEqualsOneOf(r.Header.Get(contentTypeHeader), []string{postContentTypeHeader, contentTypeHeader})
}
func isActivityPubGet(r *http.Request) bool {
return r.Method == "GET" && headerEqualsOneOf(r.Header.Get(acceptHeader), []string{getAcceptHeader, contentTypeHeader})
}
// isPublic determines if a target is the Public collection as defined in the
// spec, including JSON-LD compliant collections.
func isPublic(s string) bool {
return s == publicActivityPub || s == publicJsonLD || s == publicJsonLDAS
}
// dereference makes an HTTP GET request to an IRI in order to obtain the
// ActivityStream representation.
func dereference(c *http.Client, u url.URL, agent string) ([]byte, error) {
// TODO: (section 7.1) The server MUST dereference the collection (with the user's credentials)
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return nil, err
}
req.Header.Add(acceptHeader, getAcceptHeader)
req.Header.Add("Accept-Charset", "utf-8")
req.Header.Add("Date", time.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05")+" GMT")
req.Header.Add("User-Agent", fmt.Sprintf("%s (go-fed ActivityPub)", agent))
resp, err := c.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("Request to %s failed (%d): %s", u.String(), resp.StatusCode, resp.Status)
}
return ioutil.ReadAll(resp.Body)
}
// TODO: (Section 7) HTTP caching mechanisms [RFC7234] SHOULD be respected when appropriate, both when receiving responses from other servers as well as sending responses to other servers.
// prepare takes a DeliverableObject and returns a list of the proper recipient
// target URIs. Additionally, the DeliverableObject will have any hidden
// hidden recipients ("bto" and "bcc") stripped from it.
func (c *Client) prepare(o DeliverableObject) ([]url.URL, error) {
var r []url.URL
r = append(r, getToIRIs(o)...)
r = append(r, getBToIRIs(o)...)
r = append(r, getCcIRIs(o)...)
r = append(r, getBccIRIs(o)...)
r = append(r, getAudienceIRIs(o)...)
i, err := c.resolveInboxes(r, 0, c.MaxDepth)
if err != nil {
return nil, err
}
targets := getInboxes(i)
ignore := getActorsInboxes(o)
r = dedupeIRIs(targets, ignore)
stripHiddenRecipients(o)
return r, nil
}
// resolveInboxes takes a list of Actor id URIs and returns them as concrete
// instances of ActorObject. It applies recursively when it encounters a target
// that is a Collection or OrderedCollection.
func (c *Client) resolveInboxes(r []url.URL, depth int, max int) ([]ActorObject, error) {
if depth >= max {
return nil, nil
}
a := make([]ActorObject, 0, len(r))
for _, u := range r {
// Do not retry here -- if a dereference fails, then fail the
// entire delivery.
resp, err := dereference(c.Client, u, c.Agent)
if err != nil {
return nil, err
}
var m map[string]interface{}
if err = json.Unmarshal(resp, &m); err != nil {
return nil, err
}
var actor ActorObject
var co *streams.Collection
var oc *streams.OrderedCollection
var cp *streams.CollectionPage
var ocp *streams.OrderedCollectionPage
// Set AT MOST one of: co, oc, cp, ocp
// If none of these are set, attempt to use actor
if err = toActorCollectionResolver(&actor, &co, &oc, &cp, &ocp).Deserialize(m); err != nil {
return nil, err
}
// If a recipient is a Collection or OrderedCollection, then the
// server MUST dereference the collection. Note that this also
// applies to CollectionPage and OrderedCollectionPage.
var uris []url.URL
if co != nil {
uris := getURIsInItemer(co.Raw())
actors, err := c.resolveInboxes(uris, depth+1, max)
if err != nil {
return nil, err
}
a = append(a, actors...)
} else if oc != nil {
uris := getURIsInOrderedItemer(oc.Raw())
actors, err := c.resolveInboxes(uris, depth+1, max)
if err != nil {
return nil, err
}
a = append(a, actors...)
} else if cp != nil {
cb := func(c vocab.CollectionPageType) error {
uris = getURIsInItemer(c)
return nil
}
err := doForCollectionPage(c.Client, c.Agent, cb, cp.Raw())
if err != nil {
return nil, err
}
actors, err := c.resolveInboxes(uris, depth+1, max)
if err != nil {
return nil, err
}
a = append(a, actors...)
} else if ocp != nil {
cb := func(c vocab.OrderedCollectionPageType) error {
uris = getURIsInOrderedItemer(c)
return nil
}
err := doForOrderedCollectionPage(c.Client, c.Agent, cb, ocp.Raw())
if err != nil {
return nil, err
}
actors, err := c.resolveInboxes(uris, depth+1, max)
if err != nil {
return nil, err
}
a = append(a, actors...)
} else if actor != nil {
a = append(a, actor)
}
}
return a, nil
}
// getInboxes extracts the 'inbox' IRIs from actors.
func getInboxes(a []ActorObject) []url.URL {
// TODO: implement
return nil
}
// getActorsInboxes attempts to find the inbox URIs for the "actor" and
// "attributedTo" originators on the object. If the inbox URIs are not found,
// then the one or more actors are resolved as usual, which may result in this
// server pinging itself.
func getActorsInboxes(a ActorObject) []url.URL {
// TODO: implement
return nil
}
// stripHiddenRecipients removes "bto" and "bcc" from the DeliverableObject.
// Note that this requirement of the specification is under "Section 6: Client
// to Server Interactions", the Social API, and not the Federative API.
func stripHiddenRecipients(o DeliverableObject) {
for o.BtoLen() > 0 {
if o.IsBtoObject(0) {
o.RemoveBtoObject(0)
} else if o.IsBtoLink(0) {
o.RemoveBtoLink(0)
} else if o.IsBtoIRI(0) {
o.RemoveBtoIRI(0)
}
}
for o.BccLen() > 0 {
if o.IsBccObject(0) {
o.RemoveBccObject(0)
} else if o.IsBccLink(0) {
o.RemoveBccLink(0)
} else if o.IsBtoIRI(0) {
o.RemoveBccIRI(0)
}
}
}
// dedupeIRIs will deduplicate final inbox IRIs. The ignore list is applied to
// the final list
func dedupeIRIs(recipients, ignored []url.URL) (out []url.URL) {
ignoredMap := make(map[url.URL]bool, len(ignored))
for _, elem := range ignored {
ignoredMap[elem] = true
}
outMap := make(map[url.URL]bool, len(recipients))
for k, _ := range outMap {
if !ignoredMap[k] {
out = append(out, k)
}
}
return
}
func getToIRIs(o DeliverableObject) []url.URL {
var r []url.URL
for i := 0; i < o.ToLen(); i++ {
if o.IsToObject(i) {
obj := o.GetToObject(i)
if obj.HasId() {
r = append(r, obj.GetId())
}
} else if o.IsToLink(i) {
l := o.GetToLink(i)
if l.HasHref() {
r = append(r, l.GetHref())
}
} else if o.IsToIRI(i) {
r = append(r, o.GetToIRI(i))
}
}
return r
}
func getBToIRIs(o DeliverableObject) []url.URL {
var r []url.URL
for i := 0; i < o.BtoLen(); i++ {
if o.IsBtoObject(i) {
obj := o.GetBtoObject(i)
if obj.HasId() {
r = append(r, obj.GetId())
}
} else if o.IsBtoLink(i) {
l := o.GetBtoLink(i)
if l.HasHref() {
r = append(r, l.GetHref())
}
} else if o.IsBtoIRI(i) {
r = append(r, o.GetBtoIRI(i))
}
}
return r
}
func getCcIRIs(o DeliverableObject) []url.URL {
var r []url.URL
for i := 0; i < o.CcLen(); i++ {
if o.IsCcObject(i) {
obj := o.GetCcObject(i)
if obj.HasId() {
r = append(r, obj.GetId())
}
} else if o.IsCcLink(i) {
l := o.GetCcLink(i)
if l.HasHref() {
r = append(r, l.GetHref())
}
} else if o.IsCcIRI(i) {
r = append(r, o.GetCcIRI(i))
}
}
return r
}
func getBccIRIs(o DeliverableObject) []url.URL {
var r []url.URL
for i := 0; i < o.BccLen(); i++ {
if o.IsBccObject(i) {
obj := o.GetBccObject(i)
if obj.HasId() {
r = append(r, obj.GetId())
}
} else if o.IsBccLink(i) {
l := o.GetBccLink(i)
if l.HasHref() {
r = append(r, l.GetHref())
}
} else if o.IsBccIRI(i) {
r = append(r, o.GetBccIRI(i))
}
}
return r
}
func getAudienceIRIs(o DeliverableObject) []url.URL {
var r []url.URL
for i := 0; i < o.AudienceLen(); i++ {
if o.IsAudienceObject(i) {
obj := o.GetAudienceObject(i)
if obj.HasId() {
r = append(r, obj.GetId())
}
} else if o.IsAudienceLink(i) {
l := o.GetAudienceLink(i)
if l.HasHref() {
r = append(r, l.GetHref())
}
} else if o.IsAudienceIRI(i) {
r = append(r, o.GetAudienceIRI(i))
}
}
return r
}
// doForCollectionPage applies a function over a collection and its subsequent
// pages recursively. It returns the first non-nil error it encounters.
func doForCollectionPage(h *http.Client, agent string, cb func(c vocab.CollectionPageType) error, c vocab.CollectionPageType) error {
err := cb(c)
if err != nil {
return err
}
if c.IsNextCollectionPage() {
// Handle this one weird trick that other peers HATE federating
// with.
return doForCollectionPage(h, agent, cb, c.GetNextCollectionPage())
} else if c.IsNextLink() {
l := c.GetNextLink()
if l.HasHref() {
u := l.GetHref()
resp, err := dereference(h, u, agent)
if err != nil {
return err
}
var m map[string]interface{}
err = json.Unmarshal(resp, &m)
if err != nil {
return err
}
next, err := toCollectionPage(m)
if err != nil {
return err
}
if next != nil {
return doForCollectionPage(h, agent, cb, next.Raw())
}
}
} else if c.IsNextIRI() {
u := c.GetNextIRI()
resp, err := dereference(h, u, agent)
if err != nil {
return err
}
var m map[string]interface{}
err = json.Unmarshal(resp, &m)
if err != nil {
return err
}
next, err := toCollectionPage(m)
if err != nil {
return err
}
if next != nil {
return doForCollectionPage(h, agent, cb, next.Raw())
}
}
return nil
}
// doForOrderedCollectionPage applies a function over a collection and its
// subsequent pages recursively. It returns the first non-nil error it
// encounters.
func doForOrderedCollectionPage(h *http.Client, agent string, cb func(c vocab.OrderedCollectionPageType) error, c vocab.OrderedCollectionPageType) error {
err := cb(c)
if err != nil {
return err
}
if c.IsNextOrderedCollectionPage() {
// Handle this one weird trick that other peers HATE federating
// with.
return doForOrderedCollectionPage(h, agent, cb, c.GetNextOrderedCollectionPage())
} else if c.IsNextLink() {
l := c.GetNextLink()
if l.HasHref() {
u := l.GetHref()
resp, err := dereference(h, u, agent)
if err != nil {
return err
}
var m map[string]interface{}
err = json.Unmarshal(resp, &m)
if err != nil {
return err
}
next, err := toOrderedCollectionPage(m)
if err != nil {
return err
}
if next != nil {
return doForOrderedCollectionPage(h, agent, cb, next.Raw())
}
}
} else if c.IsNextIRI() {
u := c.GetNextIRI()
resp, err := dereference(h, u, agent)
if err != nil {
return err
}
var m map[string]interface{}
err = json.Unmarshal(resp, &m)
if err != nil {
return err
}
next, err := toOrderedCollectionPage(m)
if err != nil {
return err
}
if next != nil {
return doForOrderedCollectionPage(h, agent, cb, next.Raw())
}
}
return nil
}
type itemer interface {
ItemsLen() (l int)
IsItemsObject(index int) (ok bool)
GetItemsObject(index int) (v vocab.ObjectType)
IsItemsLink(index int) (ok bool)
GetItemsLink(index int) (v vocab.LinkType)
IsItemsIRI(index int) (ok bool)
GetItemsIRI(index int) (v url.URL)
}
// getURIsInItemer will extract 'items' from the provided Collection or
// CollectionPage.
func getURIsInItemer(i itemer) []url.URL {
// TODO: Implement
return nil
}
type orderedItemer interface {
OrderedItemsLen() (l int)
IsOrderedItemsObject(index int) (ok bool)
GetOrderedItemsObject(index int) (v vocab.ObjectType)
IsOrderedItemsLink(index int) (ok bool)
GetOrderedItemsLink(index int) (v vocab.LinkType)
IsOrderedItemsIRI(index int) (ok bool)
GetOrderedItemsIRI(index int) (v url.URL)
}
// getURIsInOrderedItemer will extract 'items' from the provided
// OrderedCollection or OrderedCollectionPage.
func getURIsInOrderedItemer(i orderedItemer) []url.URL {
// TODO: Implement
return nil
}

73
pub/resolvers.go ノーマルファイル
ファイルの表示

@ -0,0 +1,73 @@
package pub
import (
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/vocab"
"net/url"
)
func toActorResolver(a *ActorObject) *streams.Resolver {
return &streams.Resolver{
AnyObjectCallback: func(i vocab.ObjectType) error {
if o, ok := i.(ActorObject); ok {
*a = o
}
return nil
},
}
}
func toActorCollectionResolver(a *ActorObject, c **streams.Collection, oc **streams.OrderedCollection, cp **streams.CollectionPage, ocp **streams.OrderedCollectionPage) *streams.Resolver {
r := toActorResolver(a)
r.CollectionCallback = func(i *streams.Collection) error {
*c = i
return nil
}
r.OrderedCollectionCallback = func(i *streams.OrderedCollection) error {
*oc = i
return nil
}
r.CollectionPageCallback = func(i *streams.CollectionPage) error {
*cp = i
return nil
}
r.OrderedCollectionPageCallback = func(i *streams.OrderedCollectionPage) error {
*ocp = i
return nil
}
return r
}
func toIdResolver(ok *bool, u *url.URL) *streams.Resolver {
return &streams.Resolver{
AnyObjectCallback: func(i vocab.ObjectType) error {
*ok = i.HasId()
if *ok {
*u = i.GetId()
}
return nil
},
}
}
func toCollectionPage(m map[string]interface{}) (c *streams.CollectionPage, err error) {
r := &streams.Resolver{
CollectionPageCallback: func(i *streams.CollectionPage) error {
c = i
return nil
},
}
err = r.Deserialize(m)
return
}
func toOrderedCollectionPage(m map[string]interface{}) (c *streams.OrderedCollectionPage, err error) {
r := &streams.Resolver{
OrderedCollectionPageCallback: func(i *streams.OrderedCollectionPage) error {
c = i
return nil
},
}
err = r.Deserialize(m)
return
}

ファイルの表示

@ -134,6 +134,8 @@ type Resolver struct {
TombstoneCallback func(*Tombstone) error
// Callback function for the Mention type
MentionCallback func(*Mention) error
// Callback function for any type that satisfies the vocab.ObjectType interface.
AnyObjectCallback func(vocab.ObjectType) error
}
// dispatch routes the given type to the appropriate Resolver callback.
@ -678,6 +680,11 @@ func (t *Resolver) dispatch(i interface{}) (handled bool, err error) {
}
}
// End generateResolver for type 'Mention'
if obj, ok := i.(vocab.ObjectType); ok {
if t.AnyObjectCallback != nil {
return true, t.AnyObjectCallback(obj)
}
}
return false, fmt.Errorf("The interface did not match any known types: %T", i)
}
@ -10351,6 +10358,120 @@ func (t *OrderedCollection) SetOrderedItemsLink(i vocab.LinkType) {
}
// GetCurrent attempts to get this 'current' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollection) GetCurrent() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsCurrentIRI() {
k = t.raw.GetCurrentIRI()
if handled {
r = Resolved
}
} else if t.raw.IsCurrentOrderedCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsCurrentLink() {
r = RawResolutionNeeded
}
return
}
// HasCurrent returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollection) HasCurrent() (p Presence) {
p = NoPresence
if t.raw.IsCurrentIRI() {
p = ConvenientPresence
} else if t.raw.IsCurrentOrderedCollectionPage() {
p = RawPresence
} else if t.raw.IsCurrentLink() {
p = RawPresence
}
return
}
// SetCurrent sets the value for property 'current'.
func (t *OrderedCollection) SetCurrent(k url.URL) {
t.raw.SetCurrentIRI(k)
}
// GetFirst attempts to get this 'first' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollection) GetFirst() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsFirstIRI() {
k = t.raw.GetFirstIRI()
if handled {
r = Resolved
}
} else if t.raw.IsFirstOrderedCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsFirstLink() {
r = RawResolutionNeeded
}
return
}
// HasFirst returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollection) HasFirst() (p Presence) {
p = NoPresence
if t.raw.IsFirstIRI() {
p = ConvenientPresence
} else if t.raw.IsFirstOrderedCollectionPage() {
p = RawPresence
} else if t.raw.IsFirstLink() {
p = RawPresence
}
return
}
// SetFirst sets the value for property 'first'.
func (t *OrderedCollection) SetFirst(k url.URL) {
t.raw.SetFirstIRI(k)
}
// GetLast attempts to get this 'last' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollection) GetLast() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsLastIRI() {
k = t.raw.GetLastIRI()
if handled {
r = Resolved
}
} else if t.raw.IsLastOrderedCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsLastLink() {
r = RawResolutionNeeded
}
return
}
// HasLast returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollection) HasLast() (p Presence) {
p = NoPresence
if t.raw.IsLastIRI() {
p = ConvenientPresence
} else if t.raw.IsLastOrderedCollectionPage() {
p = RawPresence
} else if t.raw.IsLastLink() {
p = RawPresence
}
return
}
// SetLast sets the value for property 'last'.
func (t *OrderedCollection) SetLast(k url.URL) {
t.raw.SetLastIRI(k)
}
// GetTotalItems attempts to get this 'totalItems' property as a int64. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollection) GetTotalItems() (r Resolution, k int64) {
r = Unresolved
@ -10385,173 +10506,6 @@ func (t *OrderedCollection) SetTotalItems(k int64) {
}
// GetCurrent attempts to get this 'current' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollection) GetCurrent() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsCurrentIRI() {
k = t.raw.GetCurrentIRI()
if handled {
r = Resolved
}
} else if t.raw.IsCurrentCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsCurrentLink() {
r = RawResolutionNeeded
}
return
}
// HasCurrent returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollection) HasCurrent() (p Presence) {
p = NoPresence
if t.raw.IsCurrentIRI() {
p = ConvenientPresence
} else if t.raw.IsCurrentCollectionPage() {
p = RawPresence
} else if t.raw.IsCurrentLink() {
p = RawPresence
}
return
}
// SetCurrent sets the value for property 'current'.
func (t *OrderedCollection) SetCurrent(k url.URL) {
t.raw.SetCurrentIRI(k)
}
// GetFirst attempts to get this 'first' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollection) GetFirst() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsFirstIRI() {
k = t.raw.GetFirstIRI()
if handled {
r = Resolved
}
} else if t.raw.IsFirstCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsFirstLink() {
r = RawResolutionNeeded
}
return
}
// HasFirst returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollection) HasFirst() (p Presence) {
p = NoPresence
if t.raw.IsFirstIRI() {
p = ConvenientPresence
} else if t.raw.IsFirstCollectionPage() {
p = RawPresence
} else if t.raw.IsFirstLink() {
p = RawPresence
}
return
}
// SetFirst sets the value for property 'first'.
func (t *OrderedCollection) SetFirst(k url.URL) {
t.raw.SetFirstIRI(k)
}
// GetLast attempts to get this 'last' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollection) GetLast() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsLastIRI() {
k = t.raw.GetLastIRI()
if handled {
r = Resolved
}
} else if t.raw.IsLastCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsLastLink() {
r = RawResolutionNeeded
}
return
}
// HasLast returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollection) HasLast() (p Presence) {
p = NoPresence
if t.raw.IsLastIRI() {
p = ConvenientPresence
} else if t.raw.IsLastCollectionPage() {
p = RawPresence
} else if t.raw.IsLastLink() {
p = RawPresence
}
return
}
// SetLast sets the value for property 'last'.
func (t *OrderedCollection) SetLast(k url.URL) {
t.raw.SetLastIRI(k)
}
// LenItems returns the number of values this property contains. Each index be used with HasItems to determine if ResolveItems is safe to call or if raw handling would be needed.%!(EXTRA string=items)
func (t *OrderedCollection) LenItems() (idx int) {
return t.raw.ItemsLen()
}
// ResolveItems passes the actual concrete type to the resolver for handing property items. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollection) ResolveItems(r *Resolver, idx int) (s Resolution, err error) {
s = Unresolved
handled := false
if t.raw.IsItemsObject(idx) {
handled, err = r.dispatch(t.raw.GetItemsObject(idx))
if handled {
s = Resolved
}
} else if t.raw.IsItemsLink(idx) {
handled, err = r.dispatch(t.raw.GetItemsLink(idx))
if handled {
s = Resolved
}
} else if t.raw.IsItemsIRI(idx) {
s = RawResolutionNeeded
}
return
}
// HasItems returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollection) HasItems(idx int) (p Presence) {
p = NoPresence
if t.raw.IsItemsObject(idx) {
p = ConvenientPresence
} else if t.raw.IsItemsLink(idx) {
p = ConvenientPresence
} else if t.raw.IsItemsIRI(idx) {
p = RawPresence
}
return
}
// AddItems adds an 'Object' typed value.
func (t *OrderedCollection) AddItems(i vocab.ObjectType) {
t.raw.AddItemsObject(i)
}
// SetItemsLink adds a 'Link' typed value.
func (t *OrderedCollection) SetItemsLink(i vocab.LinkType) {
t.raw.AddItemsLink(i)
}
// GetAltitude attempts to get this 'altitude' property as a float64. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollection) GetAltitude() (r Resolution, k float64) {
r = Unresolved
@ -14607,6 +14561,82 @@ func (t *OrderedCollectionPage) SetStartIndex(k int64) {
}
// GetNext attempts to get this 'next' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollectionPage) GetNext() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsNextIRI() {
k = t.raw.GetNextIRI()
if handled {
r = Resolved
}
} else if t.raw.IsNextOrderedCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsNextLink() {
r = RawResolutionNeeded
}
return
}
// HasNext returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollectionPage) HasNext() (p Presence) {
p = NoPresence
if t.raw.IsNextIRI() {
p = ConvenientPresence
} else if t.raw.IsNextOrderedCollectionPage() {
p = RawPresence
} else if t.raw.IsNextLink() {
p = RawPresence
}
return
}
// SetNext sets the value for property 'next'.
func (t *OrderedCollectionPage) SetNext(k url.URL) {
t.raw.SetNextIRI(k)
}
// GetPrev attempts to get this 'prev' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollectionPage) GetPrev() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsPrevIRI() {
k = t.raw.GetPrevIRI()
if handled {
r = Resolved
}
} else if t.raw.IsPrevOrderedCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsPrevLink() {
r = RawResolutionNeeded
}
return
}
// HasPrev returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollectionPage) HasPrev() (p Presence) {
p = NoPresence
if t.raw.IsPrevIRI() {
p = ConvenientPresence
} else if t.raw.IsPrevOrderedCollectionPage() {
p = RawPresence
} else if t.raw.IsPrevLink() {
p = RawPresence
}
return
}
// SetPrev sets the value for property 'prev'.
func (t *OrderedCollectionPage) SetPrev(k url.URL) {
t.raw.SetPrevIRI(k)
}
// LenOrderedItems returns the number of values this property contains. Each index be used with HasOrderedItems to determine if ResolveOrderedItems is safe to call or if raw handling would be needed.%!(EXTRA string=orderedItems)
func (t *OrderedCollectionPage) LenOrderedItems() (idx int) {
return t.raw.OrderedItemsLen()
@ -14660,6 +14690,120 @@ func (t *OrderedCollectionPage) SetOrderedItemsLink(i vocab.LinkType) {
}
// GetCurrent attempts to get this 'current' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollectionPage) GetCurrent() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsCurrentIRI() {
k = t.raw.GetCurrentIRI()
if handled {
r = Resolved
}
} else if t.raw.IsCurrentOrderedCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsCurrentLink() {
r = RawResolutionNeeded
}
return
}
// HasCurrent returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollectionPage) HasCurrent() (p Presence) {
p = NoPresence
if t.raw.IsCurrentIRI() {
p = ConvenientPresence
} else if t.raw.IsCurrentOrderedCollectionPage() {
p = RawPresence
} else if t.raw.IsCurrentLink() {
p = RawPresence
}
return
}
// SetCurrent sets the value for property 'current'.
func (t *OrderedCollectionPage) SetCurrent(k url.URL) {
t.raw.SetCurrentIRI(k)
}
// GetFirst attempts to get this 'first' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollectionPage) GetFirst() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsFirstIRI() {
k = t.raw.GetFirstIRI()
if handled {
r = Resolved
}
} else if t.raw.IsFirstOrderedCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsFirstLink() {
r = RawResolutionNeeded
}
return
}
// HasFirst returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollectionPage) HasFirst() (p Presence) {
p = NoPresence
if t.raw.IsFirstIRI() {
p = ConvenientPresence
} else if t.raw.IsFirstOrderedCollectionPage() {
p = RawPresence
} else if t.raw.IsFirstLink() {
p = RawPresence
}
return
}
// SetFirst sets the value for property 'first'.
func (t *OrderedCollectionPage) SetFirst(k url.URL) {
t.raw.SetFirstIRI(k)
}
// GetLast attempts to get this 'last' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollectionPage) GetLast() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsLastIRI() {
k = t.raw.GetLastIRI()
if handled {
r = Resolved
}
} else if t.raw.IsLastOrderedCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsLastLink() {
r = RawResolutionNeeded
}
return
}
// HasLast returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollectionPage) HasLast() (p Presence) {
p = NoPresence
if t.raw.IsLastIRI() {
p = ConvenientPresence
} else if t.raw.IsLastOrderedCollectionPage() {
p = RawPresence
} else if t.raw.IsLastLink() {
p = RawPresence
}
return
}
// SetLast sets the value for property 'last'.
func (t *OrderedCollectionPage) SetLast(k url.URL) {
t.raw.SetLastIRI(k)
}
// GetTotalItems attempts to get this 'totalItems' property as a int64. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollectionPage) GetTotalItems() (r Resolution, k int64) {
r = Unresolved
@ -14694,173 +14838,6 @@ func (t *OrderedCollectionPage) SetTotalItems(k int64) {
}
// GetCurrent attempts to get this 'current' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollectionPage) GetCurrent() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsCurrentIRI() {
k = t.raw.GetCurrentIRI()
if handled {
r = Resolved
}
} else if t.raw.IsCurrentCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsCurrentLink() {
r = RawResolutionNeeded
}
return
}
// HasCurrent returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollectionPage) HasCurrent() (p Presence) {
p = NoPresence
if t.raw.IsCurrentIRI() {
p = ConvenientPresence
} else if t.raw.IsCurrentCollectionPage() {
p = RawPresence
} else if t.raw.IsCurrentLink() {
p = RawPresence
}
return
}
// SetCurrent sets the value for property 'current'.
func (t *OrderedCollectionPage) SetCurrent(k url.URL) {
t.raw.SetCurrentIRI(k)
}
// GetFirst attempts to get this 'first' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollectionPage) GetFirst() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsFirstIRI() {
k = t.raw.GetFirstIRI()
if handled {
r = Resolved
}
} else if t.raw.IsFirstCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsFirstLink() {
r = RawResolutionNeeded
}
return
}
// HasFirst returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollectionPage) HasFirst() (p Presence) {
p = NoPresence
if t.raw.IsFirstIRI() {
p = ConvenientPresence
} else if t.raw.IsFirstCollectionPage() {
p = RawPresence
} else if t.raw.IsFirstLink() {
p = RawPresence
}
return
}
// SetFirst sets the value for property 'first'.
func (t *OrderedCollectionPage) SetFirst(k url.URL) {
t.raw.SetFirstIRI(k)
}
// GetLast attempts to get this 'last' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollectionPage) GetLast() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsLastIRI() {
k = t.raw.GetLastIRI()
if handled {
r = Resolved
}
} else if t.raw.IsLastCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsLastLink() {
r = RawResolutionNeeded
}
return
}
// HasLast returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollectionPage) HasLast() (p Presence) {
p = NoPresence
if t.raw.IsLastIRI() {
p = ConvenientPresence
} else if t.raw.IsLastCollectionPage() {
p = RawPresence
} else if t.raw.IsLastLink() {
p = RawPresence
}
return
}
// SetLast sets the value for property 'last'.
func (t *OrderedCollectionPage) SetLast(k url.URL) {
t.raw.SetLastIRI(k)
}
// LenItems returns the number of values this property contains. Each index be used with HasItems to determine if ResolveItems is safe to call or if raw handling would be needed.%!(EXTRA string=items)
func (t *OrderedCollectionPage) LenItems() (idx int) {
return t.raw.ItemsLen()
}
// ResolveItems passes the actual concrete type to the resolver for handing property items. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollectionPage) ResolveItems(r *Resolver, idx int) (s Resolution, err error) {
s = Unresolved
handled := false
if t.raw.IsItemsObject(idx) {
handled, err = r.dispatch(t.raw.GetItemsObject(idx))
if handled {
s = Resolved
}
} else if t.raw.IsItemsLink(idx) {
handled, err = r.dispatch(t.raw.GetItemsLink(idx))
if handled {
s = Resolved
}
} else if t.raw.IsItemsIRI(idx) {
s = RawResolutionNeeded
}
return
}
// HasItems returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollectionPage) HasItems(idx int) (p Presence) {
p = NoPresence
if t.raw.IsItemsObject(idx) {
p = ConvenientPresence
} else if t.raw.IsItemsLink(idx) {
p = ConvenientPresence
} else if t.raw.IsItemsIRI(idx) {
p = RawPresence
}
return
}
// AddItems adds an 'Object' typed value.
func (t *OrderedCollectionPage) AddItems(i vocab.ObjectType) {
t.raw.AddItemsObject(i)
}
// SetItemsLink adds a 'Link' typed value.
func (t *OrderedCollectionPage) SetItemsLink(i vocab.LinkType) {
t.raw.AddItemsLink(i)
}
// GetAltitude attempts to get this 'altitude' property as a float64. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollectionPage) GetAltitude() (r Resolution, k float64) {
r = Unresolved
@ -16734,82 +16711,6 @@ func (t *OrderedCollectionPage) SetPartOf(i vocab.LinkType) {
}
// GetNext attempts to get this 'next' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollectionPage) GetNext() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsNextIRI() {
k = t.raw.GetNextIRI()
if handled {
r = Resolved
}
} else if t.raw.IsNextCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsNextLink() {
r = RawResolutionNeeded
}
return
}
// HasNext returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollectionPage) HasNext() (p Presence) {
p = NoPresence
if t.raw.IsNextIRI() {
p = ConvenientPresence
} else if t.raw.IsNextCollectionPage() {
p = RawPresence
} else if t.raw.IsNextLink() {
p = RawPresence
}
return
}
// SetNext sets the value for property 'next'.
func (t *OrderedCollectionPage) SetNext(k url.URL) {
t.raw.SetNextIRI(k)
}
// GetPrev attempts to get this 'prev' property as a url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *OrderedCollectionPage) GetPrev() (r Resolution, k url.URL) {
r = Unresolved
handled := false
if t.raw.IsPrevIRI() {
k = t.raw.GetPrevIRI()
if handled {
r = Resolved
}
} else if t.raw.IsPrevCollectionPage() {
r = RawResolutionNeeded
} else if t.raw.IsPrevLink() {
r = RawResolutionNeeded
}
return
}
// HasPrev returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *OrderedCollectionPage) HasPrev() (p Presence) {
p = NoPresence
if t.raw.IsPrevIRI() {
p = ConvenientPresence
} else if t.raw.IsPrevCollectionPage() {
p = RawPresence
} else if t.raw.IsPrevLink() {
p = RawPresence
}
return
}
// SetPrev sets the value for property 'prev'.
func (t *OrderedCollectionPage) SetPrev(k url.URL) {
t.raw.SetPrevIRI(k)
}
// Indicates that the actor accepts the object. The target property can be used in certain circumstances to indicate the context into which the object has been accepted. This is a convenience wrapper of a type with the same name in the vocab package. Accessing it with the Raw function allows direct manipulaton of the object, and does not provide the same integrity guarantees as this package.
type Accept struct {
// The raw type from the vocab package

ファイルの表示

@ -46,6 +46,12 @@ var (
URI: baseURI + "OrderedCollection",
Notes: "A subtype of Collection in which members of the logical collection are assumed to always be strictly ordered.",
Extends: []*Type{collectionType},
WithoutProperties: []*PropertyType{
itemsPropertyType,
currentPropertyType,
firstPropertyType,
lastPropertyType,
},
}
collectionPageType = &Type{
Name: "CollectionPage",
@ -58,6 +64,14 @@ var (
URI: baseURI + "OrderedCollectionPage",
Notes: "Used to represent ordered subsets of items from an OrderedCollection. Refer to the Activity Streams 2.0 Core for a complete description of the OrderedCollectionPage object.",
Extends: []*Type{orderedCollectionType, collectionPageType},
WithoutProperties: []*PropertyType{
itemsPropertyType,
currentPropertyType,
firstPropertyType,
lastPropertyType,
nextPropertyType,
prevPropertyType,
},
}
AllCoreTypes = []*Type{
@ -505,6 +519,15 @@ var (
Functional: true,
PreferIRIConvenience: true,
}
currentOrderedPropertyType = &PropertyType{
Name: "current",
URI: propertyBaseURI + "current",
Notes: "In a paged OrderedCollection, indicates the page that contains the most recently updated member items.",
Domain: []DomainReference{{T: collectionType}},
Range: []RangeReference{{T: orderedCollectionPageType}, {T: linkType}},
Functional: true,
PreferIRIConvenience: true,
}
firstPropertyType = &PropertyType{
Name: "first",
URI: propertyBaseURI + "first",
@ -514,6 +537,15 @@ var (
Functional: true,
PreferIRIConvenience: true,
}
firstOrderedPropertyType = &PropertyType{
Name: "first",
URI: propertyBaseURI + "first",
Notes: "In a paged OrderedCollection, indicates the furthest preceeding page of items in the collection.",
Domain: []DomainReference{{T: collectionType}},
Range: []RangeReference{{T: orderedCollectionPageType}, {T: linkType}},
Functional: true,
PreferIRIConvenience: true,
}
generatorPropertyType = &PropertyType{
Name: "generator",
URI: propertyBaseURI + "generator",
@ -559,6 +591,15 @@ var (
Functional: true,
PreferIRIConvenience: true,
}
lastOrderedPropertyType = &PropertyType{
Name: "last",
URI: propertyBaseURI + "last",
Notes: "In a paged OrderedCollection, indicates the furthest proceeding page of the collection.",
Domain: []DomainReference{{T: collectionType}},
Range: []RangeReference{{T: orderedCollectionPageType}, {T: linkType}},
Functional: true,
PreferIRIConvenience: true,
}
locationPropertyType = &PropertyType{
Name: "location",
URI: propertyBaseURI + "location",
@ -617,6 +658,15 @@ var (
Functional: true,
PreferIRIConvenience: true,
}
nextOrderedPropertyType = &PropertyType{
Name: "next",
URI: propertyBaseURI + "next",
Notes: "In a paged OrderedCollection, indicates the next page of items.",
Domain: []DomainReference{{T: orderedCollectionPageType}},
Range: []RangeReference{{T: orderedCollectionPageType}, {T: linkType}},
Functional: true,
PreferIRIConvenience: true,
}
objectPropertyType = &PropertyType{
Name: "object",
URI: propertyBaseURI + "object",
@ -633,6 +683,15 @@ var (
Functional: true,
PreferIRIConvenience: true,
}
prevOrderedPropertyType = &PropertyType{
Name: "prev",
URI: propertyBaseURI + "prev",
Notes: "In a paged OrderedCollection, identifies the previous page of items.",
Domain: []DomainReference{{T: orderedCollectionPageType}},
Range: []RangeReference{{T: orderedCollectionPageType}, {T: linkType}},
Functional: true,
PreferIRIConvenience: true,
}
previewPropertyType = &PropertyType{
Name: "preview",
URI: propertyBaseURI + "preview",
@ -1042,13 +1101,16 @@ var (
ccPropertyType,
contextPropertyType,
currentPropertyType,
currentOrderedPropertyType,
firstPropertyType,
firstOrderedPropertyType,
generatorPropertyType,
iconPropertyType,
imagePropertyType,
inReplyToPropertyType,
instrumentPropertyType,
lastPropertyType,
lastOrderedPropertyType,
locationPropertyType,
itemsPropertyType,
orderedItemsPropertyType,
@ -1057,8 +1119,10 @@ var (
closedPropertyType,
originPropertyType,
nextPropertyType,
nextOrderedPropertyType,
objectPropertyType,
prevPropertyType,
prevOrderedPropertyType,
previewPropertyType,
resultPropertyType,
repliesPropertyType,
@ -1747,6 +1811,9 @@ func init() {
}
orderedCollectionType.Properties = []*PropertyType{
orderedItemsPropertyType, // Missing from spec!
currentOrderedPropertyType,
firstOrderedPropertyType,
lastOrderedPropertyType,
}
collectionPageType.Properties = []*PropertyType{
partOfPropertyType,
@ -1755,6 +1822,8 @@ func init() {
}
orderedCollectionPageType.Properties = []*PropertyType{
startIndexPropertyType,
nextOrderedPropertyType,
prevOrderedPropertyType,
}
// ExtendedType properties

ファイルの表示

@ -11,9 +11,9 @@ type Type struct {
}
func (t *Type) GetProperties() []*PropertyType {
omit := make(map[string]bool)
omit := make(map[*PropertyType]bool)
for _, v := range t.WithoutProperties {
omit[v.Name] = true
omit[v] = true
}
var parentProps []*PropertyType
for _, p := range t.Extends {
@ -22,7 +22,7 @@ func (t *Type) GetProperties() []*PropertyType {
properties := make([]*PropertyType, 0, len(t.Properties)+len(parentProps))
set := make(map[string]bool)
for _, v := range t.Properties {
if !omit[v.Name] {
if !omit[v] {
if !set[v.Name] {
properties = append(properties, v)
set[v.Name] = true
@ -30,7 +30,7 @@ func (t *Type) GetProperties() []*PropertyType {
}
}
for _, v := range parentProps {
if !omit[v.Name] {
if !omit[v] {
if !set[v.Name] {
properties = append(properties, v)
set[v.Name] = true

ファイルの表示

@ -68,6 +68,7 @@ func generateResolver(types []*defs.Type) *defs.StructDef {
c := fmt.Sprintf("Callback function for the %s type", t.Name)
this.M = append(this.M, &defs.StructMember{name, sig, c})
}
this.M = append(this.M, &defs.StructMember{"AnyObjectCallback", "func(vocab.ObjectType) error", "Callback function for any type that satisfies the vocab.ObjectType interface."})
this.F = []*defs.MemberFunctionDef{
{
Name: dispatchFnName,
@ -90,6 +91,11 @@ func generateResolver(types []*defs.Type) *defs.StructDef {
b.WriteString("}\n")
b.WriteString(fmt.Sprintf("// End generateResolver for type '%s'\n", t.Name))
}
b.WriteString("if obj, ok := i.(vocab.ObjectType); ok {\n")
b.WriteString("if t.AnyObjectCallback != nil {\n")
b.WriteString("return true, t.AnyObjectCallback(obj)")
b.WriteString("}\n")
b.WriteString("}\n")
b.WriteString("return false, fmt.Errorf(\"The interface did not match any known types: %T\", i)\n")
return b.String()
},

バイナリ
tools/streams/streams 実行可能ファイル

バイナリファイルは表示されません。

ファイルの表示

@ -230,7 +230,15 @@ func generateSerializeFunction(t *defs.Type, this *defs.StructDef, fragments []s
}
func generateWithoutProperties(d *defs.Type, this *defs.StructDef, it *defs.InterfaceDef) {
hasNamed := make(map[string]bool, 0)
for _, p := range d.GetProperties() {
hasNamed[p.Name] = true
}
for _, t := range d.WithoutProperties {
if hasNamed[t.Name] {
// No need to stub -- already has a replacement.
continue
}
clonedThis := &defs.StructDef{
Typename: this.Typename,
Comment: this.Comment,
@ -276,6 +284,7 @@ func generateWithoutProperties(d *defs.Type, this *defs.StructDef, it *defs.Inte
this.F = append(this.F, f)
} else {
f.Body = func() string { return "\n" }
this.F = append(this.F, f)
}
}
}

ファイル差分が大きすぎるため省略します 差分を読み込み