Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
7367409b78 | |||
b05423b549 | |||
d7fe75e8a6 |
|
@ -778,7 +778,7 @@ func (a *Activity) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadActivity(val, a)
|
||||
return LoadActivity(val, a)
|
||||
}
|
||||
|
||||
func fmtActivityProps(w io.Writer) func(*Activity) error {
|
||||
|
@ -831,12 +831,12 @@ func ToActivity(it Item) (*Activity, error) {
|
|||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (a Activity) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
if !writeActivityJSONValue(&b, a) {
|
||||
if !WriteActivityJSONValue(&b, a) {
|
||||
return nil, nil
|
||||
}
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
|
62
actor.go
62
actor.go
|
@ -210,27 +210,27 @@ func (p *PublicKey) UnmarshalJSON(data []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return loadPublicKey(val, p)
|
||||
return LoadPublicKey(val, p)
|
||||
}
|
||||
|
||||
func (p PublicKey) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
notEmpty := true
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
if v, err := p.ID.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = !writeJSONProp(&b, "id", v)
|
||||
notEmpty = !WriteJSONProp(&b, "id", v)
|
||||
}
|
||||
if len(p.Owner) > 0 {
|
||||
notEmpty = writeIRIJSONProp(&b, "owner", p.Owner) || notEmpty
|
||||
notEmpty = WriteIRIJSONProp(&b, "owner", p.Owner) || notEmpty
|
||||
}
|
||||
if len(p.PublicKeyPem) > 0 {
|
||||
if pem, err := json.Marshal(p.PublicKeyPem); err == nil {
|
||||
notEmpty = writeJSONProp(&b, "publicKeyPem", pem) || notEmpty
|
||||
notEmpty = WriteJSONProp(&b, "publicKeyPem", pem) || notEmpty
|
||||
}
|
||||
}
|
||||
|
||||
if notEmpty {
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
@ -356,52 +356,52 @@ func (a *Actor) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadActor(val, a)
|
||||
return LoadActor(val, a)
|
||||
}
|
||||
|
||||
func (a Actor) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
notEmpty := false
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
OnObject(a, func(o *Object) error {
|
||||
notEmpty = writeObjectJSONValue(&b, *o)
|
||||
notEmpty = WriteObjectJSONValue(&b, *o)
|
||||
return nil
|
||||
})
|
||||
if a.Inbox != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "inbox", a.Inbox) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "inbox", a.Inbox) || notEmpty
|
||||
}
|
||||
if a.Outbox != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "outbox", a.Outbox) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "outbox", a.Outbox) || notEmpty
|
||||
}
|
||||
if a.Following != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "following", a.Following) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "following", a.Following) || notEmpty
|
||||
}
|
||||
if a.Followers != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "followers", a.Followers) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "followers", a.Followers) || notEmpty
|
||||
}
|
||||
if a.Liked != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "liked", a.Liked) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "liked", a.Liked) || notEmpty
|
||||
}
|
||||
if a.PreferredUsername != nil {
|
||||
notEmpty = writeNaturalLanguageJSONProp(&b, "preferredUsername", a.PreferredUsername) || notEmpty
|
||||
notEmpty = WriteNaturalLanguageJSONProp(&b, "preferredUsername", a.PreferredUsername) || notEmpty
|
||||
}
|
||||
if a.Endpoints != nil {
|
||||
if v, err := a.Endpoints.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = writeJSONProp(&b, "endpoints", v) || notEmpty
|
||||
notEmpty = WriteJSONProp(&b, "endpoints", v) || notEmpty
|
||||
}
|
||||
}
|
||||
if len(a.Streams) > 0 {
|
||||
notEmpty = writeItemCollectionJSONProp(&b, "streams", a.Streams)
|
||||
notEmpty = WriteItemCollectionJSONProp(&b, "streams", a.Streams)
|
||||
}
|
||||
if len(a.PublicKey.PublicKeyPem)+len(a.PublicKey.ID) > 0 {
|
||||
if v, err := a.PublicKey.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = writeJSONProp(&b, "publicKey", v) || notEmpty
|
||||
notEmpty = WriteJSONProp(&b, "publicKey", v) || notEmpty
|
||||
}
|
||||
}
|
||||
|
||||
if notEmpty {
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
@ -419,8 +419,8 @@ func (a Actor) Format(s fmt.State, verb rune) {
|
|||
// This mapping may be nested inside the actor document as the value or may be a link to
|
||||
// a JSON-LD document with these properties.
|
||||
type Endpoints struct {
|
||||
// UploadMedia Upload endpoint URI for this user for binary data.
|
||||
UploadMedia Item `jsonld:"uploadMedia,omitempty"`
|
||||
// UpLoadMedia UpLoad endpoint URI for this user for binary data.
|
||||
UpLoadMedia Item `jsonld:"upLoadMedia,omitempty"`
|
||||
// OauthAuthorizationEndpoint Endpoint URI so this actor's clients may access remote ActivityStreams objects which require authentication
|
||||
// to access. To use this endpoint, the client posts an x-www-form-urlencoded id parameter with the value being
|
||||
// the id of the requested ActivityStreams object.
|
||||
|
@ -450,7 +450,7 @@ func (e *Endpoints) UnmarshalJSON(data []byte) error {
|
|||
}
|
||||
e.OauthAuthorizationEndpoint = JSONGetItem(val, "oauthAuthorizationEndpoint")
|
||||
e.OauthTokenEndpoint = JSONGetItem(val, "oauthTokenEndpoint")
|
||||
e.UploadMedia = JSONGetItem(val, "uploadMedia")
|
||||
e.UpLoadMedia = JSONGetItem(val, "upLoadMedia")
|
||||
e.ProvideClientKey = JSONGetItem(val, "provideClientKey")
|
||||
e.SignClientKey = JSONGetItem(val, "signClientKey")
|
||||
e.SharedInbox = JSONGetItem(val, "sharedInbox")
|
||||
|
@ -462,27 +462,27 @@ func (e Endpoints) MarshalJSON() ([]byte, error) {
|
|||
b := make([]byte, 0)
|
||||
notEmpty := false
|
||||
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
if e.OauthAuthorizationEndpoint != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "oauthAuthorizationEndpoint", e.OauthAuthorizationEndpoint) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "oauthAuthorizationEndpoint", e.OauthAuthorizationEndpoint) || notEmpty
|
||||
}
|
||||
if e.OauthTokenEndpoint != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "oauthTokenEndpoint", e.OauthTokenEndpoint) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "oauthTokenEndpoint", e.OauthTokenEndpoint) || notEmpty
|
||||
}
|
||||
if e.ProvideClientKey != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "provideClientKey", e.ProvideClientKey) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "provideClientKey", e.ProvideClientKey) || notEmpty
|
||||
}
|
||||
if e.SignClientKey != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "signClientKey", e.SignClientKey) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "signClientKey", e.SignClientKey) || notEmpty
|
||||
}
|
||||
if e.SharedInbox != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "sharedInbox", e.SharedInbox) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "sharedInbox", e.SharedInbox) || notEmpty
|
||||
}
|
||||
if e.UploadMedia != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "uploadMedia", e.UploadMedia) || notEmpty
|
||||
if e.UpLoadMedia != nil {
|
||||
notEmpty = WriteItemJSONProp(&b, "upLoadMedia", e.UpLoadMedia) || notEmpty
|
||||
}
|
||||
if notEmpty {
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
|
|
@ -238,34 +238,34 @@ func (c *Collection) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadCollection(val, c)
|
||||
return LoadCollection(val, c)
|
||||
}
|
||||
|
||||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (c Collection) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
notEmpty := false
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
OnObject(c, func(o *Object) error {
|
||||
notEmpty = writeObjectJSONValue(&b, *o)
|
||||
notEmpty = WriteObjectJSONValue(&b, *o)
|
||||
return nil
|
||||
})
|
||||
if c.Current != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "current", c.Current) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "current", c.Current) || notEmpty
|
||||
}
|
||||
if c.First != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "first", c.First) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "first", c.First) || notEmpty
|
||||
}
|
||||
if c.Last != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "last", c.Last) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "last", c.Last) || notEmpty
|
||||
}
|
||||
notEmpty = writeIntJSONProp(&b, "totalItems", int64(c.TotalItems)) || notEmpty
|
||||
notEmpty = WriteIntJSONProp(&b, "totalItems", int64(c.TotalItems)) || notEmpty
|
||||
if c.Items != nil {
|
||||
notEmpty = writeItemCollectionJSONProp(&b, "items", c.Items) || notEmpty
|
||||
notEmpty = WriteItemCollectionJSONProp(&b, "items", c.Items) || notEmpty
|
||||
}
|
||||
if notEmpty {
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
|
|
@ -195,43 +195,43 @@ func (c *CollectionPage) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadCollectionPage(val, c)
|
||||
return LoadCollectionPage(val, c)
|
||||
}
|
||||
|
||||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (c CollectionPage) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
notEmpty := false
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
OnObject(c, func(o *Object) error {
|
||||
notEmpty = writeObjectJSONValue(&b, *o)
|
||||
notEmpty = WriteObjectJSONValue(&b, *o)
|
||||
return nil
|
||||
})
|
||||
if c.PartOf != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "partOf", c.PartOf) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "partOf", c.PartOf) || notEmpty
|
||||
}
|
||||
if c.Current != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "current", c.Current) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "current", c.Current) || notEmpty
|
||||
}
|
||||
if c.First != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "first", c.First) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "first", c.First) || notEmpty
|
||||
}
|
||||
if c.Last != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "last", c.Last) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "last", c.Last) || notEmpty
|
||||
}
|
||||
if c.Next != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "next", c.Next) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "next", c.Next) || notEmpty
|
||||
}
|
||||
if c.Prev != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "prev", c.Prev) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "prev", c.Prev) || notEmpty
|
||||
}
|
||||
notEmpty = writeIntJSONProp(&b, "totalItems", int64(c.TotalItems)) || notEmpty
|
||||
notEmpty = WriteIntJSONProp(&b, "totalItems", int64(c.TotalItems)) || notEmpty
|
||||
if c.Items != nil {
|
||||
notEmpty = writeItemCollectionJSONProp(&b, "items", c.Items) || notEmpty
|
||||
notEmpty = WriteItemCollectionJSONProp(&b, "items", c.Items) || notEmpty
|
||||
}
|
||||
if notEmpty {
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
|
|
@ -146,7 +146,7 @@ func JSONGetPublicKey(val *fastjson.Value, prop string) PublicKey {
|
|||
if val == nil {
|
||||
return key
|
||||
}
|
||||
loadPublicKey(val, &key)
|
||||
LoadPublicKey(val, &key)
|
||||
return key
|
||||
}
|
||||
|
||||
|
@ -186,61 +186,61 @@ func itemFn(val *fastjson.Value) (Item, error) {
|
|||
fallthrough
|
||||
case ObjectType, ArticleType, AudioType, DocumentType, EventType, ImageType, NoteType, PageType, VideoType:
|
||||
err = OnObject(i, func(ob *Object) error {
|
||||
return loadObject(val, ob)
|
||||
return LoadObject(val, ob)
|
||||
})
|
||||
case LinkType, MentionType:
|
||||
err = OnLink(i, func(l *Link) error {
|
||||
return loadLink(val, l)
|
||||
return LoadLink(val, l)
|
||||
})
|
||||
case ActivityType, AcceptType, AddType, AnnounceType, BlockType, CreateType, DeleteType, DislikeType,
|
||||
FlagType, FollowType, IgnoreType, InviteType, JoinType, LeaveType, LikeType, ListenType, MoveType, OfferType,
|
||||
RejectType, ReadType, RemoveType, TentativeRejectType, TentativeAcceptType, UndoType, UpdateType, ViewType:
|
||||
err = OnActivity(i, func(act *Activity) error {
|
||||
return loadActivity(val, act)
|
||||
return LoadActivity(val, act)
|
||||
})
|
||||
case IntransitiveActivityType, ArriveType, TravelType:
|
||||
err = OnIntransitiveActivity(i, func(act *IntransitiveActivity) error {
|
||||
return loadIntransitiveActivity(val, act)
|
||||
return LoadIntransitiveActivity(val, act)
|
||||
})
|
||||
case ActorType, ApplicationType, GroupType, OrganizationType, PersonType, ServiceType:
|
||||
err = OnActor(i, func(a *Actor) error {
|
||||
return loadActor(val, a)
|
||||
return LoadActor(val, a)
|
||||
})
|
||||
case CollectionType:
|
||||
err = OnCollection(i, func(c *Collection) error {
|
||||
return loadCollection(val, c)
|
||||
return LoadCollection(val, c)
|
||||
})
|
||||
case OrderedCollectionType:
|
||||
err = OnOrderedCollection(i, func(c *OrderedCollection) error {
|
||||
return loadOrderedCollection(val, c)
|
||||
return LoadOrderedCollection(val, c)
|
||||
})
|
||||
case CollectionPageType:
|
||||
err = OnCollectionPage(i, func(p *CollectionPage) error {
|
||||
return loadCollectionPage(val, p)
|
||||
return LoadCollectionPage(val, p)
|
||||
})
|
||||
case OrderedCollectionPageType:
|
||||
err = OnOrderedCollectionPage(i, func(p *OrderedCollectionPage) error {
|
||||
return loadOrderedCollectionPage(val, p)
|
||||
return LoadOrderedCollectionPage(val, p)
|
||||
})
|
||||
case PlaceType:
|
||||
err = OnPlace(i, func(p *Place) error {
|
||||
return loadPlace(val, p)
|
||||
return LoadPlace(val, p)
|
||||
})
|
||||
case ProfileType:
|
||||
err = OnProfile(i, func(p *Profile) error {
|
||||
return loadProfile(val, p)
|
||||
return LoadProfile(val, p)
|
||||
})
|
||||
case RelationshipType:
|
||||
err = OnRelationship(i, func(r *Relationship) error {
|
||||
return loadRelationship(val, r)
|
||||
return LoadRelationship(val, r)
|
||||
})
|
||||
case TombstoneType:
|
||||
err = OnTombstone(i, func(t *Tombstone) error {
|
||||
return loadTombstone(val, t)
|
||||
return LoadTombstone(val, t)
|
||||
})
|
||||
case QuestionType:
|
||||
err = OnQuestion(i, func(q *Question) error {
|
||||
return loadQuestion(val, q)
|
||||
return LoadQuestion(val, q)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -446,7 +446,7 @@ func JSONGetActorEndpoints(val *fastjson.Value, prop string) *Endpoints {
|
|||
return e
|
||||
}
|
||||
|
||||
func loadObject(val *fastjson.Value, o *Object) error {
|
||||
func LoadObject(val *fastjson.Value, o *Object) error {
|
||||
if ItemTyperFunc == nil {
|
||||
ItemTyperFunc = GetItemByType
|
||||
}
|
||||
|
@ -484,9 +484,9 @@ func loadObject(val *fastjson.Value, o *Object) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadIntransitiveActivity(val *fastjson.Value, i *IntransitiveActivity) error {
|
||||
func LoadIntransitiveActivity(val *fastjson.Value, i *IntransitiveActivity) error {
|
||||
OnObject(i, func(o *Object) error {
|
||||
return loadObject(val, o)
|
||||
return LoadObject(val, o)
|
||||
})
|
||||
i.Actor = JSONGetItem(val, "actor")
|
||||
i.Target = JSONGetItem(val, "target")
|
||||
|
@ -496,17 +496,17 @@ func loadIntransitiveActivity(val *fastjson.Value, i *IntransitiveActivity) erro
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadActivity(val *fastjson.Value, a *Activity) error {
|
||||
func LoadActivity(val *fastjson.Value, a *Activity) error {
|
||||
OnIntransitiveActivity(a, func(i *IntransitiveActivity) error {
|
||||
return loadIntransitiveActivity(val, i)
|
||||
return LoadIntransitiveActivity(val, i)
|
||||
})
|
||||
a.Object = JSONGetItem(val, "object")
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadQuestion(val *fastjson.Value, q *Question) error {
|
||||
func LoadQuestion(val *fastjson.Value, q *Question) error {
|
||||
OnIntransitiveActivity(q, func(i *IntransitiveActivity) error {
|
||||
return loadIntransitiveActivity(val, i)
|
||||
return LoadIntransitiveActivity(val, i)
|
||||
})
|
||||
q.OneOf = JSONGetItem(val, "oneOf")
|
||||
q.AnyOf = JSONGetItem(val, "anyOf")
|
||||
|
@ -514,9 +514,9 @@ func loadQuestion(val *fastjson.Value, q *Question) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadActor(val *fastjson.Value, a *Actor) error {
|
||||
func LoadActor(val *fastjson.Value, a *Actor) error {
|
||||
OnObject(a, func(o *Object) error {
|
||||
return loadObject(val, o)
|
||||
return LoadObject(val, o)
|
||||
})
|
||||
a.PreferredUsername = JSONGetNaturalLanguageField(val, "preferredUsername")
|
||||
a.Followers = JSONGetItem(val, "followers")
|
||||
|
@ -530,9 +530,9 @@ func loadActor(val *fastjson.Value, a *Actor) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadCollection(val *fastjson.Value, c *Collection) error {
|
||||
func LoadCollection(val *fastjson.Value, c *Collection) error {
|
||||
OnObject(c, func(o *Object) error {
|
||||
return loadObject(val, o)
|
||||
return LoadObject(val, o)
|
||||
})
|
||||
c.Current = JSONGetItem(val, "current")
|
||||
c.First = JSONGetItem(val, "first")
|
||||
|
@ -542,9 +542,9 @@ func loadCollection(val *fastjson.Value, c *Collection) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadCollectionPage(val *fastjson.Value, c *CollectionPage) error {
|
||||
func LoadCollectionPage(val *fastjson.Value, c *CollectionPage) error {
|
||||
OnCollection(c, func(c *Collection) error {
|
||||
return loadCollection(val, c)
|
||||
return LoadCollection(val, c)
|
||||
})
|
||||
c.Next = JSONGetItem(val, "next")
|
||||
c.Prev = JSONGetItem(val, "prev")
|
||||
|
@ -552,9 +552,9 @@ func loadCollectionPage(val *fastjson.Value, c *CollectionPage) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadOrderedCollection(val *fastjson.Value, c *OrderedCollection) error {
|
||||
func LoadOrderedCollection(val *fastjson.Value, c *OrderedCollection) error {
|
||||
OnObject(c, func(o *Object) error {
|
||||
return loadObject(val, o)
|
||||
return LoadObject(val, o)
|
||||
})
|
||||
c.Current = JSONGetItem(val, "current")
|
||||
c.First = JSONGetItem(val, "first")
|
||||
|
@ -564,9 +564,9 @@ func loadOrderedCollection(val *fastjson.Value, c *OrderedCollection) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadOrderedCollectionPage(val *fastjson.Value, c *OrderedCollectionPage) error {
|
||||
func LoadOrderedCollectionPage(val *fastjson.Value, c *OrderedCollectionPage) error {
|
||||
OnOrderedCollection(c, func(c *OrderedCollection) error {
|
||||
return loadOrderedCollection(val, c)
|
||||
return LoadOrderedCollection(val, c)
|
||||
})
|
||||
c.Next = JSONGetItem(val, "next")
|
||||
c.Prev = JSONGetItem(val, "prev")
|
||||
|
@ -575,9 +575,9 @@ func loadOrderedCollectionPage(val *fastjson.Value, c *OrderedCollectionPage) er
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadPlace(val *fastjson.Value, p *Place) error {
|
||||
func LoadPlace(val *fastjson.Value, p *Place) error {
|
||||
OnObject(p, func(o *Object) error {
|
||||
return loadObject(val, o)
|
||||
return LoadObject(val, o)
|
||||
})
|
||||
p.Accuracy = JSONGetFloat(val, "accuracy")
|
||||
p.Altitude = JSONGetFloat(val, "altitude")
|
||||
|
@ -588,17 +588,17 @@ func loadPlace(val *fastjson.Value, p *Place) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadProfile(val *fastjson.Value, p *Profile) error {
|
||||
func LoadProfile(val *fastjson.Value, p *Profile) error {
|
||||
OnObject(p, func(o *Object) error {
|
||||
return loadObject(val, o)
|
||||
return LoadObject(val, o)
|
||||
})
|
||||
p.Describes = JSONGetItem(val, "describes")
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadRelationship(val *fastjson.Value, r *Relationship) error {
|
||||
func LoadRelationship(val *fastjson.Value, r *Relationship) error {
|
||||
OnObject(r, func(o *Object) error {
|
||||
return loadObject(val, o)
|
||||
return LoadObject(val, o)
|
||||
})
|
||||
r.Subject = JSONGetItem(val, "subject")
|
||||
r.Object = JSONGetItem(val, "object")
|
||||
|
@ -606,16 +606,16 @@ func loadRelationship(val *fastjson.Value, r *Relationship) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadTombstone(val *fastjson.Value, t *Tombstone) error {
|
||||
func LoadTombstone(val *fastjson.Value, t *Tombstone) error {
|
||||
OnObject(t, func(o *Object) error {
|
||||
return loadObject(val, o)
|
||||
return LoadObject(val, o)
|
||||
})
|
||||
t.FormerType = ActivityVocabularyType(JSONGetString(val, "formerType"))
|
||||
t.Deleted = JSONGetTime(val, "deleted")
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadLink(val *fastjson.Value, l *Link) error {
|
||||
func LoadLink(val *fastjson.Value, l *Link) error {
|
||||
if ItemTyperFunc == nil {
|
||||
ItemTyperFunc = GetItemByType
|
||||
}
|
||||
|
@ -653,7 +653,7 @@ func loadLink(val *fastjson.Value, l *Link) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func loadPublicKey(val *fastjson.Value, p *PublicKey) error {
|
||||
func LoadPublicKey(val *fastjson.Value, p *PublicKey) error {
|
||||
if id := val.GetStringBytes("id"); len(id) > 0 {
|
||||
p.ID = ID(id)
|
||||
}
|
||||
|
|
210
encoding_json.go
210
encoding_json.go
|
@ -9,102 +9,102 @@ import (
|
|||
"github.com/go-ap/jsonld"
|
||||
)
|
||||
|
||||
func writeComma(b *[]byte) {
|
||||
func WriteComma(b *[]byte) {
|
||||
if len(*b) > 1 && (*b)[len(*b)-1] != ',' {
|
||||
*b = append(*b, ',')
|
||||
}
|
||||
}
|
||||
|
||||
func writeJSONProp(b *[]byte, name string, val []byte) (notEmpty bool) {
|
||||
func WriteJSONProp(b *[]byte, name string, val []byte) (notEmpty bool) {
|
||||
if len(val) == 0 {
|
||||
return false
|
||||
}
|
||||
writeComma(b)
|
||||
success := writePropJSONName(b, name) && writeJSONValue(b, val)
|
||||
WriteComma(b)
|
||||
success := WritePropJSONName(b, name) && WriteJSONValue(b, val)
|
||||
if !success {
|
||||
*b = (*b)[:len(*b)-1]
|
||||
}
|
||||
return success
|
||||
}
|
||||
|
||||
func write(b *[]byte, c ...byte) {
|
||||
func Write(b *[]byte, c ...byte) {
|
||||
*b = append(*b, c...)
|
||||
}
|
||||
|
||||
func writeS(b *[]byte, s string) {
|
||||
func WriteS(b *[]byte, s string) {
|
||||
*b = append(*b, s...)
|
||||
}
|
||||
|
||||
func writePropJSONName(b *[]byte, s string) (notEmpty bool) {
|
||||
func WritePropJSONName(b *[]byte, s string) (notEmpty bool) {
|
||||
if len(s) == 0 {
|
||||
return false
|
||||
}
|
||||
write(b, '"')
|
||||
writeS(b, s)
|
||||
write(b, '"', ':')
|
||||
Write(b, '"')
|
||||
WriteS(b, s)
|
||||
Write(b, '"', ':')
|
||||
return true
|
||||
}
|
||||
|
||||
func writeJSONValue(b *[]byte, s []byte) (notEmpty bool) {
|
||||
func WriteJSONValue(b *[]byte, s []byte) (notEmpty bool) {
|
||||
if len(s) == 0 {
|
||||
return false
|
||||
}
|
||||
write(b, s...)
|
||||
Write(b, s...)
|
||||
return true
|
||||
}
|
||||
|
||||
func writeNaturalLanguageJSONProp(b *[]byte, n string, nl NaturalLanguageValues) (notEmpty bool) {
|
||||
func WriteNaturalLanguageJSONProp(b *[]byte, n string, nl NaturalLanguageValues) (notEmpty bool) {
|
||||
l := nl.Count()
|
||||
if l > 1 {
|
||||
n += "Map"
|
||||
}
|
||||
if v, err := nl.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
return writeJSONProp(b, n, v)
|
||||
return WriteJSONProp(b, n, v)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func writeStringJSONProp(b *[]byte, n string, s string) (notEmpty bool) {
|
||||
return writeJSONProp(b, n, []byte(fmt.Sprintf(`"%s"`, s)))
|
||||
func WriteStringJSONProp(b *[]byte, n string, s string) (notEmpty bool) {
|
||||
return WriteJSONProp(b, n, []byte(fmt.Sprintf(`"%s"`, s)))
|
||||
}
|
||||
|
||||
func writeBoolJSONProp(b *[]byte, n string, t bool) (notEmpty bool) {
|
||||
return writeJSONProp(b, n, []byte(fmt.Sprintf(`"%t"`, t)))
|
||||
func WriteBoolJSONProp(b *[]byte, n string, t bool) (notEmpty bool) {
|
||||
return WriteJSONProp(b, n, []byte(fmt.Sprintf(`"%t"`, t)))
|
||||
}
|
||||
|
||||
func writeIntJSONProp(b *[]byte, n string, d int64) (notEmpty bool) {
|
||||
return writeJSONProp(b, n, []byte(fmt.Sprintf("%d", d)))
|
||||
func WriteIntJSONProp(b *[]byte, n string, d int64) (notEmpty bool) {
|
||||
return WriteJSONProp(b, n, []byte(fmt.Sprintf("%d", d)))
|
||||
}
|
||||
|
||||
func writeFloatJSONProp(b *[]byte, n string, f float64) (notEmpty bool) {
|
||||
return writeJSONProp(b, n, []byte(fmt.Sprintf("%f", f)))
|
||||
func WriteFloatJSONProp(b *[]byte, n string, f float64) (notEmpty bool) {
|
||||
return WriteJSONProp(b, n, []byte(fmt.Sprintf("%f", f)))
|
||||
}
|
||||
|
||||
func writeTimeJSONProp(b *[]byte, n string, t time.Time) (notEmpty bool) {
|
||||
func WriteTimeJSONProp(b *[]byte, n string, t time.Time) (notEmpty bool) {
|
||||
var tb []byte
|
||||
write(&tb, '"')
|
||||
writeS(&tb, t.UTC().Format(time.RFC3339))
|
||||
write(&tb, '"')
|
||||
return writeJSONProp(b, n, tb)
|
||||
Write(&tb, '"')
|
||||
WriteS(&tb, t.UTC().Format(time.RFC3339))
|
||||
Write(&tb, '"')
|
||||
return WriteJSONProp(b, n, tb)
|
||||
}
|
||||
|
||||
func writeDurationJSONProp(b *[]byte, n string, d time.Duration) (notEmpty bool) {
|
||||
func WriteDurationJSONProp(b *[]byte, n string, d time.Duration) (notEmpty bool) {
|
||||
if v, err := xsd.Marshal(d); err == nil {
|
||||
return writeJSONProp(b, n, v)
|
||||
return WriteJSONProp(b, n, v)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func writeIRIJSONProp(b *[]byte, n string, i LinkOrIRI) (notEmpty bool) {
|
||||
func WriteIRIJSONProp(b *[]byte, n string, i LinkOrIRI) (notEmpty bool) {
|
||||
url := i.GetLink().String()
|
||||
if len(url) == 0 {
|
||||
return false
|
||||
}
|
||||
writeStringJSONProp(b, n, url)
|
||||
WriteStringJSONProp(b, n, url)
|
||||
return true
|
||||
}
|
||||
|
||||
func writeItemJSONProp(b *[]byte, n string, i Item) (notEmpty bool) {
|
||||
func WriteItemJSONProp(b *[]byte, n string, i Item) (notEmpty bool) {
|
||||
if i == nil {
|
||||
return notEmpty
|
||||
}
|
||||
|
@ -113,244 +113,244 @@ func writeItemJSONProp(b *[]byte, n string, i Item) (notEmpty bool) {
|
|||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return writeJSONProp(b, n, v)
|
||||
return WriteJSONProp(b, n, v)
|
||||
}
|
||||
return notEmpty
|
||||
}
|
||||
|
||||
func writeStringJSONValue(b *[]byte, s string) (notEmpty bool) {
|
||||
func WriteStringJSONValue(b *[]byte, s string) (notEmpty bool) {
|
||||
if len(s) == 0 {
|
||||
return false
|
||||
}
|
||||
write(b, '"')
|
||||
writeS(b, s)
|
||||
write(b, '"')
|
||||
Write(b, '"')
|
||||
WriteS(b, s)
|
||||
Write(b, '"')
|
||||
return true
|
||||
}
|
||||
|
||||
func writeItemCollectionJSONValue(b *[]byte, col ItemCollection) (notEmpty bool) {
|
||||
func WriteItemCollectionJSONValue(b *[]byte, col ItemCollection) (notEmpty bool) {
|
||||
if len(col) == 0 {
|
||||
return notEmpty
|
||||
}
|
||||
writeCommaIfNotEmpty := func(notEmpty bool) {
|
||||
WriteCommaIfNotEmpty := func(notEmpty bool) {
|
||||
if notEmpty {
|
||||
write(b, ',')
|
||||
Write(b, ',')
|
||||
}
|
||||
}
|
||||
write(b, '[')
|
||||
Write(b, '[')
|
||||
for i, it := range col {
|
||||
if im, ok := it.(json.Marshaler); ok {
|
||||
v, err := im.MarshalJSON()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
writeCommaIfNotEmpty(i > 0)
|
||||
write(b, v...)
|
||||
WriteCommaIfNotEmpty(i > 0)
|
||||
Write(b, v...)
|
||||
}
|
||||
}
|
||||
write(b, ']')
|
||||
Write(b, ']')
|
||||
return true
|
||||
}
|
||||
|
||||
func writeItemCollectionJSONProp(b *[]byte, n string, col ItemCollection) (notEmpty bool) {
|
||||
func WriteItemCollectionJSONProp(b *[]byte, n string, col ItemCollection) (notEmpty bool) {
|
||||
if len(col) == 0 {
|
||||
return notEmpty
|
||||
}
|
||||
writeComma(b)
|
||||
success := writePropJSONName(b, n) && writeItemCollectionJSONValue(b, col)
|
||||
WriteComma(b)
|
||||
success := WritePropJSONName(b, n) && WriteItemCollectionJSONValue(b, col)
|
||||
if !success {
|
||||
*b = (*b)[:len(*b)-1]
|
||||
}
|
||||
return success
|
||||
}
|
||||
|
||||
func writeObjectJSONValue(b *[]byte, o Object) (notEmpty bool) {
|
||||
func WriteObjectJSONValue(b *[]byte, o Object) (notEmpty bool) {
|
||||
if v, err := o.ID.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = writeJSONProp(b, "id", v) || notEmpty
|
||||
notEmpty = WriteJSONProp(b, "id", v) || notEmpty
|
||||
}
|
||||
if v, err := o.Type.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = writeJSONProp(b, "type", v) || notEmpty
|
||||
notEmpty = WriteJSONProp(b, "type", v) || notEmpty
|
||||
}
|
||||
if v, err := o.MediaType.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = writeJSONProp(b, "mediaType", v) || notEmpty
|
||||
notEmpty = WriteJSONProp(b, "mediaType", v) || notEmpty
|
||||
}
|
||||
if len(o.Name) > 0 {
|
||||
notEmpty = writeNaturalLanguageJSONProp(b, "name", o.Name) || notEmpty
|
||||
notEmpty = WriteNaturalLanguageJSONProp(b, "name", o.Name) || notEmpty
|
||||
}
|
||||
if len(o.Summary) > 0 {
|
||||
notEmpty = writeNaturalLanguageJSONProp(b, "summary", o.Summary) || notEmpty
|
||||
notEmpty = WriteNaturalLanguageJSONProp(b, "summary", o.Summary) || notEmpty
|
||||
}
|
||||
if len(o.Content) > 0 {
|
||||
notEmpty = writeNaturalLanguageJSONProp(b, "content", o.Content) || notEmpty
|
||||
notEmpty = WriteNaturalLanguageJSONProp(b, "content", o.Content) || notEmpty
|
||||
}
|
||||
if o.Attachment != nil {
|
||||
notEmpty = writeItemJSONProp(b, "attachment", o.Attachment) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "attachment", o.Attachment) || notEmpty
|
||||
}
|
||||
if o.AttributedTo != nil {
|
||||
notEmpty = writeItemJSONProp(b, "attributedTo", o.AttributedTo) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "attributedTo", o.AttributedTo) || notEmpty
|
||||
}
|
||||
if o.Audience != nil {
|
||||
notEmpty = writeItemJSONProp(b, "audience", o.Audience) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "audience", o.Audience) || notEmpty
|
||||
}
|
||||
if o.Context != nil {
|
||||
notEmpty = writeItemJSONProp(b, "context", o.Context) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "context", o.Context) || notEmpty
|
||||
}
|
||||
if o.Generator != nil {
|
||||
notEmpty = writeItemJSONProp(b, "generator", o.Generator) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "generator", o.Generator) || notEmpty
|
||||
}
|
||||
if o.Icon != nil {
|
||||
notEmpty = writeItemJSONProp(b, "icon", o.Icon) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "icon", o.Icon) || notEmpty
|
||||
}
|
||||
if o.Image != nil {
|
||||
notEmpty = writeItemJSONProp(b, "image", o.Image) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "image", o.Image) || notEmpty
|
||||
}
|
||||
if o.InReplyTo != nil {
|
||||
notEmpty = writeItemJSONProp(b, "inReplyTo", o.InReplyTo) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "inReplyTo", o.InReplyTo) || notEmpty
|
||||
}
|
||||
if o.Location != nil {
|
||||
notEmpty = writeItemJSONProp(b, "location", o.Location) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "location", o.Location) || notEmpty
|
||||
}
|
||||
if o.Preview != nil {
|
||||
notEmpty = writeItemJSONProp(b, "preview", o.Preview) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "preview", o.Preview) || notEmpty
|
||||
}
|
||||
if o.Replies != nil {
|
||||
notEmpty = writeItemJSONProp(b, "replies", o.Replies) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "replies", o.Replies) || notEmpty
|
||||
}
|
||||
if o.Tag != nil {
|
||||
notEmpty = writeItemJSONProp(b, "tag", o.Tag) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "tag", o.Tag) || notEmpty
|
||||
}
|
||||
if o.URL != nil {
|
||||
notEmpty = writeItemJSONProp(b, "url", o.URL) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "url", o.URL) || notEmpty
|
||||
}
|
||||
if o.To != nil {
|
||||
notEmpty = writeItemJSONProp(b, "to", o.To) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "to", o.To) || notEmpty
|
||||
}
|
||||
if o.Bto != nil {
|
||||
notEmpty = writeItemJSONProp(b, "bto", o.Bto) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "bto", o.Bto) || notEmpty
|
||||
}
|
||||
if o.CC != nil {
|
||||
notEmpty = writeItemJSONProp(b, "cc", o.CC) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "cc", o.CC) || notEmpty
|
||||
}
|
||||
if o.BCC != nil {
|
||||
notEmpty = writeItemJSONProp(b, "bcc", o.BCC) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "bcc", o.BCC) || notEmpty
|
||||
}
|
||||
if !o.Published.IsZero() {
|
||||
notEmpty = writeTimeJSONProp(b, "published", o.Published) || notEmpty
|
||||
notEmpty = WriteTimeJSONProp(b, "published", o.Published) || notEmpty
|
||||
}
|
||||
if !o.Updated.IsZero() {
|
||||
notEmpty = writeTimeJSONProp(b, "updated", o.Updated) || notEmpty
|
||||
notEmpty = WriteTimeJSONProp(b, "updated", o.Updated) || notEmpty
|
||||
}
|
||||
if !o.StartTime.IsZero() {
|
||||
notEmpty = writeTimeJSONProp(b, "startTime", o.StartTime) || notEmpty
|
||||
notEmpty = WriteTimeJSONProp(b, "startTime", o.StartTime) || notEmpty
|
||||
}
|
||||
if !o.EndTime.IsZero() {
|
||||
notEmpty = writeTimeJSONProp(b, "endTime", o.EndTime) || notEmpty
|
||||
notEmpty = WriteTimeJSONProp(b, "endTime", o.EndTime) || notEmpty
|
||||
}
|
||||
if o.Duration != 0 {
|
||||
// TODO(marius): maybe don't use 0 as a nil value for Object types
|
||||
// which can have a valid duration of 0 - (Video, Audio, etc)
|
||||
notEmpty = writeDurationJSONProp(b, "duration", o.Duration) || notEmpty
|
||||
notEmpty = WriteDurationJSONProp(b, "duration", o.Duration) || notEmpty
|
||||
}
|
||||
if o.Likes != nil {
|
||||
notEmpty = writeItemJSONProp(b, "likes", o.Likes) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "likes", o.Likes) || notEmpty
|
||||
}
|
||||
if o.Shares != nil {
|
||||
notEmpty = writeItemJSONProp(b, "shares", o.Shares) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "shares", o.Shares) || notEmpty
|
||||
}
|
||||
if v, err := o.Source.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = writeJSONProp(b, "source", v) || notEmpty
|
||||
notEmpty = WriteJSONProp(b, "source", v) || notEmpty
|
||||
}
|
||||
return notEmpty
|
||||
}
|
||||
|
||||
func writeActivityJSONValue(b *[]byte, a Activity) (notEmpty bool) {
|
||||
func WriteActivityJSONValue(b *[]byte, a Activity) (notEmpty bool) {
|
||||
OnIntransitiveActivity(a, func(i *IntransitiveActivity) error {
|
||||
if i == nil {
|
||||
return nil
|
||||
}
|
||||
notEmpty = writeIntransitiveActivityJSONValue(b, *i) || notEmpty
|
||||
notEmpty = WriteIntransitiveActivityJSONValue(b, *i) || notEmpty
|
||||
return nil
|
||||
})
|
||||
if a.Object != nil {
|
||||
notEmpty = writeItemJSONProp(b, "object", a.Object) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "object", a.Object) || notEmpty
|
||||
}
|
||||
return notEmpty
|
||||
}
|
||||
|
||||
func writeIntransitiveActivityJSONValue(b *[]byte, i IntransitiveActivity) (notEmpty bool) {
|
||||
func WriteIntransitiveActivityJSONValue(b *[]byte, i IntransitiveActivity) (notEmpty bool) {
|
||||
OnObject(i, func(o *Object) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
notEmpty = writeObjectJSONValue(b, *o) || notEmpty
|
||||
notEmpty = WriteObjectJSONValue(b, *o) || notEmpty
|
||||
return nil
|
||||
})
|
||||
if i.Actor != nil {
|
||||
notEmpty = writeItemJSONProp(b, "actor", i.Actor) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "actor", i.Actor) || notEmpty
|
||||
}
|
||||
if i.Target != nil {
|
||||
notEmpty = writeItemJSONProp(b, "target", i.Target) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "target", i.Target) || notEmpty
|
||||
}
|
||||
if i.Result != nil {
|
||||
notEmpty = writeItemJSONProp(b, "result", i.Result) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "result", i.Result) || notEmpty
|
||||
}
|
||||
if i.Origin != nil {
|
||||
notEmpty = writeItemJSONProp(b, "origin", i.Origin) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "origin", i.Origin) || notEmpty
|
||||
}
|
||||
if i.Instrument != nil {
|
||||
notEmpty = writeItemJSONProp(b, "instrument", i.Instrument) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "instrument", i.Instrument) || notEmpty
|
||||
}
|
||||
return notEmpty
|
||||
}
|
||||
|
||||
func writeQuestionJSONValue(b *[]byte, q Question) (notEmpty bool) {
|
||||
func WriteQuestionJSONValue(b *[]byte, q Question) (notEmpty bool) {
|
||||
OnIntransitiveActivity(q, func(i *IntransitiveActivity) error {
|
||||
if i == nil {
|
||||
return nil
|
||||
}
|
||||
notEmpty = writeIntransitiveActivityJSONValue(b, *i) || notEmpty
|
||||
notEmpty = WriteIntransitiveActivityJSONValue(b, *i) || notEmpty
|
||||
return nil
|
||||
})
|
||||
if q.OneOf != nil {
|
||||
notEmpty = writeItemJSONProp(b, "oneOf", q.OneOf) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "oneOf", q.OneOf) || notEmpty
|
||||
}
|
||||
if q.AnyOf != nil {
|
||||
notEmpty = writeItemJSONProp(b, "anyOf", q.AnyOf) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "anyOf", q.AnyOf) || notEmpty
|
||||
}
|
||||
notEmpty = writeBoolJSONProp(b, "closed", q.Closed) || notEmpty
|
||||
notEmpty = WriteBoolJSONProp(b, "closed", q.Closed) || notEmpty
|
||||
return notEmpty
|
||||
}
|
||||
|
||||
func writeLinkJSONValue(b *[]byte, l Link) (notEmpty bool) {
|
||||
func WriteLinkJSONValue(b *[]byte, l Link) (notEmpty bool) {
|
||||
if v, err := l.ID.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = writeJSONProp(b, "id", v) || notEmpty
|
||||
notEmpty = WriteJSONProp(b, "id", v) || notEmpty
|
||||
}
|
||||
if v, err := l.Type.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = writeJSONProp(b, "type", v) || notEmpty
|
||||
notEmpty = WriteJSONProp(b, "type", v) || notEmpty
|
||||
}
|
||||
if v, err := l.MediaType.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = writeJSONProp(b, "mediaType", v) || notEmpty
|
||||
notEmpty = WriteJSONProp(b, "mediaType", v) || notEmpty
|
||||
}
|
||||
if len(l.Name) > 0 {
|
||||
notEmpty = writeNaturalLanguageJSONProp(b, "name", l.Name) || notEmpty
|
||||
notEmpty = WriteNaturalLanguageJSONProp(b, "name", l.Name) || notEmpty
|
||||
}
|
||||
if v, err := l.Rel.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = writeJSONProp(b, "rel", v) || notEmpty
|
||||
notEmpty = WriteJSONProp(b, "rel", v) || notEmpty
|
||||
}
|
||||
if l.Height > 0 {
|
||||
notEmpty = writeIntJSONProp(b, "height", int64(l.Height))
|
||||
notEmpty = WriteIntJSONProp(b, "height", int64(l.Height))
|
||||
}
|
||||
if l.Width > 0 {
|
||||
notEmpty = writeIntJSONProp(b, "width", int64(l.Width))
|
||||
notEmpty = WriteIntJSONProp(b, "width", int64(l.Width))
|
||||
}
|
||||
if l.Preview != nil {
|
||||
notEmpty = writeItemJSONProp(b, "rel", l.Preview) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(b, "rel", l.Preview) || notEmpty
|
||||
}
|
||||
if v, err := l.Href.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = writeJSONProp(b, "href", v) || notEmpty
|
||||
notEmpty = WriteJSONProp(b, "href", v) || notEmpty
|
||||
}
|
||||
if len(l.HrefLang) > 0 {
|
||||
notEmpty = writeStringJSONProp(b, "hrefLang", string(l.HrefLang)) || notEmpty
|
||||
notEmpty = WriteStringJSONProp(b, "hrefLang", string(l.HrefLang)) || notEmpty
|
||||
}
|
||||
return notEmpty
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func Test_write(t *testing.T) {
|
||||
func Test_Write(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
c []byte
|
||||
|
@ -22,7 +22,7 @@ func Test_write(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_writeActivity(t *testing.T) {
|
||||
func Test_WriteActivity(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
a Activity
|
||||
|
@ -36,14 +36,14 @@ func Test_writeActivity(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeActivityJSONValue(tt.args.b, tt.args.a); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeActivityJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteActivityJSONValue(tt.args.b, tt.args.a); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteActivityJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeBoolProp(t *testing.T) {
|
||||
func Test_WriteBoolProp(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
n string
|
||||
|
@ -58,14 +58,14 @@ func Test_writeBoolProp(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeBoolJSONProp(tt.args.b, tt.args.n, tt.args.t); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeBoolJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteBoolJSONProp(tt.args.b, tt.args.n, tt.args.t); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteBoolJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeComma(t *testing.T) {
|
||||
func Test_WriteComma(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ func Test_writeComma(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_writeDurationProp(t *testing.T) {
|
||||
func Test_WriteDurationProp(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
n string
|
||||
|
@ -96,14 +96,14 @@ func Test_writeDurationProp(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeDurationJSONProp(tt.args.b, tt.args.n, tt.args.d); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeDurationJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteDurationJSONProp(tt.args.b, tt.args.n, tt.args.d); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteDurationJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeFloatProp(t *testing.T) {
|
||||
func Test_WriteFloatProp(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
n string
|
||||
|
@ -118,14 +118,14 @@ func Test_writeFloatProp(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeFloatJSONProp(tt.args.b, tt.args.n, tt.args.f); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeFloatJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteFloatJSONProp(tt.args.b, tt.args.n, tt.args.f); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteFloatJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeIRIProp(t *testing.T) {
|
||||
func Test_WriteIRIProp(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
n string
|
||||
|
@ -140,14 +140,14 @@ func Test_writeIRIProp(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeIRIJSONProp(tt.args.b, tt.args.n, tt.args.i); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeIRIJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteIRIJSONProp(tt.args.b, tt.args.n, tt.args.i); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteIRIJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeIntProp(t *testing.T) {
|
||||
func Test_WriteIntProp(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
n string
|
||||
|
@ -162,14 +162,14 @@ func Test_writeIntProp(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeIntJSONProp(tt.args.b, tt.args.n, tt.args.d); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeIntJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteIntJSONProp(tt.args.b, tt.args.n, tt.args.d); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteIntJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeIntransitiveActivity(t *testing.T) {
|
||||
func Test_WriteIntransitiveActivity(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
i IntransitiveActivity
|
||||
|
@ -183,14 +183,14 @@ func Test_writeIntransitiveActivity(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeIntransitiveActivityJSONValue(tt.args.b, tt.args.i); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeIntransitiveActivityJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteIntransitiveActivityJSONValue(tt.args.b, tt.args.i); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteIntransitiveActivityJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeItemCollection(t *testing.T) {
|
||||
func Test_WriteItemCollection(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
col ItemCollection
|
||||
|
@ -204,14 +204,14 @@ func Test_writeItemCollection(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeItemCollectionJSONValue(tt.args.b, tt.args.col); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeItemCollectionJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteItemCollectionJSONValue(tt.args.b, tt.args.col); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteItemCollectionJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeItemCollectionProp(t *testing.T) {
|
||||
func Test_WriteItemCollectionProp(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
n string
|
||||
|
@ -226,14 +226,14 @@ func Test_writeItemCollectionProp(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeItemCollectionJSONProp(tt.args.b, tt.args.n, tt.args.col); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeItemCollectionJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteItemCollectionJSONProp(tt.args.b, tt.args.n, tt.args.col); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteItemCollectionJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeItemProp(t *testing.T) {
|
||||
func Test_WriteItemProp(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
n string
|
||||
|
@ -248,14 +248,14 @@ func Test_writeItemProp(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeItemJSONProp(tt.args.b, tt.args.n, tt.args.i); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeItemJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteItemJSONProp(tt.args.b, tt.args.n, tt.args.i); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteItemJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeNaturalLanguageProp(t *testing.T) {
|
||||
func Test_WriteNaturalLanguageProp(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
n string
|
||||
|
@ -270,14 +270,14 @@ func Test_writeNaturalLanguageProp(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeNaturalLanguageJSONProp(tt.args.b, tt.args.n, tt.args.nl); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeNaturalLanguageJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteNaturalLanguageJSONProp(tt.args.b, tt.args.n, tt.args.nl); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteNaturalLanguageJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeObject(t *testing.T) {
|
||||
func Test_WriteObject(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
o Object
|
||||
|
@ -291,14 +291,14 @@ func Test_writeObject(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeObjectJSONValue(tt.args.b, tt.args.o); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeObjectJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteObjectJSONValue(tt.args.b, tt.args.o); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteObjectJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeProp(t *testing.T) {
|
||||
func Test_WriteProp(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
name string
|
||||
|
@ -313,14 +313,14 @@ func Test_writeProp(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeJSONProp(tt.args.b, tt.args.name, tt.args.val); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteJSONProp(tt.args.b, tt.args.name, tt.args.val); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writePropName(t *testing.T) {
|
||||
func Test_WritePropName(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
s string
|
||||
|
@ -334,14 +334,14 @@ func Test_writePropName(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writePropJSONName(tt.args.b, tt.args.s); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writePropJSONName() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WritePropJSONName(tt.args.b, tt.args.s); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WritePropJSONName() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeQuestion(t *testing.T) {
|
||||
func Test_WriteQuestion(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
q Question
|
||||
|
@ -355,14 +355,14 @@ func Test_writeQuestion(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeQuestionJSONValue(tt.args.b, tt.args.q); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeQuestionJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteQuestionJSONValue(tt.args.b, tt.args.q); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteQuestionJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeS(t *testing.T) {
|
||||
func Test_WriteS(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
s string
|
||||
|
@ -379,7 +379,7 @@ func Test_writeS(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_writeString(t *testing.T) {
|
||||
func Test_WriteString(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
s string
|
||||
|
@ -393,14 +393,14 @@ func Test_writeString(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeStringJSONValue(tt.args.b, tt.args.s); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeStringJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteStringJSONValue(tt.args.b, tt.args.s); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteStringJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeStringProp(t *testing.T) {
|
||||
func Test_WriteStringProp(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
n string
|
||||
|
@ -415,14 +415,14 @@ func Test_writeStringProp(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeStringJSONProp(tt.args.b, tt.args.n, tt.args.s); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeStringJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteStringJSONProp(tt.args.b, tt.args.n, tt.args.s); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteStringJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeTimeProp(t *testing.T) {
|
||||
func Test_WriteTimeProp(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
n string
|
||||
|
@ -437,14 +437,14 @@ func Test_writeTimeProp(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeTimeJSONProp(tt.args.b, tt.args.n, tt.args.t); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeTimeJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteTimeJSONProp(tt.args.b, tt.args.n, tt.args.t); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteTimeJSONProp() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_writeValue(t *testing.T) {
|
||||
func Test_WriteValue(t *testing.T) {
|
||||
type args struct {
|
||||
b *[]byte
|
||||
s []byte
|
||||
|
@ -458,8 +458,8 @@ func Test_writeValue(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotNotEmpty := writeJSONValue(tt.args.b, tt.args.s); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("writeJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
if gotNotEmpty := WriteJSONValue(tt.args.b, tt.args.s); gotNotEmpty != tt.wantNotEmpty {
|
||||
t.Errorf("WriteJSONValue() = %v, want %v", gotNotEmpty, tt.wantNotEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
|||
module github.com/go-ap/activitypub
|
||||
module gitea.com/Ta180m/activitypub
|
||||
|
||||
go 1.18
|
||||
|
||||
|
|
|
@ -191,18 +191,18 @@ func (i *IntransitiveActivity) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadIntransitiveActivity(val, i)
|
||||
return LoadIntransitiveActivity(val, i)
|
||||
}
|
||||
|
||||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (i IntransitiveActivity) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
if !writeIntransitiveActivityJSONValue(&b, i) {
|
||||
if !WriteIntransitiveActivityJSONValue(&b, i) {
|
||||
return nil, nil
|
||||
}
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
|
22
iri.go
22
iri.go
|
@ -73,9 +73,9 @@ func (i IRI) MarshalJSON() ([]byte, error) {
|
|||
return nil, nil
|
||||
}
|
||||
b := make([]byte, 0)
|
||||
write(&b, '"')
|
||||
writeS(&b, i.String())
|
||||
write(&b, '"')
|
||||
Write(&b, '"')
|
||||
WriteS(&b, i.String())
|
||||
Write(&b, '"')
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
@ -175,19 +175,19 @@ func (i IRIs) MarshalJSON() ([]byte, error) {
|
|||
if len(i) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
writeCommaIfNotEmpty := func(notEmpty bool) {
|
||||
WriteCommaIfNotEmpty := func(notEmpty bool) {
|
||||
if notEmpty {
|
||||
writeS(&b, ",")
|
||||
WriteS(&b, ",")
|
||||
}
|
||||
}
|
||||
write(&b, '[')
|
||||
Write(&b, '[')
|
||||
for k, iri := range i {
|
||||
writeCommaIfNotEmpty(k > 0)
|
||||
write(&b, '"')
|
||||
writeS(&b, iri.String())
|
||||
write(&b, '"')
|
||||
WriteCommaIfNotEmpty(k > 0)
|
||||
Write(&b, '"')
|
||||
WriteS(&b, iri.String())
|
||||
Write(&b, '"')
|
||||
}
|
||||
write(&b, ']')
|
||||
Write(&b, ']')
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ func (i ItemCollection) MarshalJSON() ([]byte, error) {
|
|||
return nil, nil
|
||||
}
|
||||
b := make([]byte, 0)
|
||||
writeItemCollectionJSONValue(&b, i)
|
||||
WriteItemCollectionJSONValue(&b, i)
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
|
8
link.go
8
link.go
|
@ -102,10 +102,10 @@ func (l Link) GetType() ActivityVocabularyType {
|
|||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (l Link) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
if writeLinkJSONValue(&b, l) {
|
||||
write(&b, '}')
|
||||
if WriteLinkJSONValue(&b, l) {
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
@ -118,7 +118,7 @@ func (l *Link) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadLink(val, l)
|
||||
return LoadLink(val, l)
|
||||
}
|
||||
|
||||
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
|
||||
|
|
|
@ -460,10 +460,10 @@ func (n *NaturalLanguageValues) UnmarshalJSON(data []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText tries to load the NaturalLanguage array from the incoming Text value
|
||||
// UnmarshalText tries to Load the NaturalLanguage array from the incoming Text value
|
||||
func (n *NaturalLanguageValues) UnmarshalText(data []byte) error {
|
||||
if data[0] == '"' {
|
||||
// a quoted string - loading it to c.URL
|
||||
// a quoted string - Loading it to c.URL
|
||||
if data[len(data)-1] != '"' {
|
||||
return fmt.Errorf("invalid string value when unmarshaling %T value", n)
|
||||
}
|
||||
|
|
22
object.go
22
object.go
|
@ -93,7 +93,7 @@ type (
|
|||
// IsCollection shows if the current item represents an ItemCollection
|
||||
IsCollection() bool
|
||||
}
|
||||
// Mapper interface allows external objects to implement their own mechanism for loading information
|
||||
// Mapper interface allows external objects to implement their own mechanism for Loading information
|
||||
// from an ActivityStreams vocabulary object
|
||||
Mapper interface {
|
||||
// FromActivityStreams maps an ActivityStreams object to another struct representation
|
||||
|
@ -109,7 +109,7 @@ func (a ActivityVocabularyType) MarshalJSON() ([]byte, error) {
|
|||
return nil, nil
|
||||
}
|
||||
b := make([]byte, 0)
|
||||
writeStringJSONValue(&b, string(a))
|
||||
WriteStringJSONValue(&b, string(a))
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
@ -289,16 +289,16 @@ func (o *Object) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadObject(val, o)
|
||||
return LoadObject(val, o)
|
||||
}
|
||||
|
||||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (o Object) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
if writeObjectJSONValue(&b, o) {
|
||||
write(&b, '}')
|
||||
if WriteObjectJSONValue(&b, o) {
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
@ -564,7 +564,7 @@ func (m MimeType) MarshalJSON() ([]byte, error) {
|
|||
return nil, nil
|
||||
}
|
||||
b := make([]byte, 0)
|
||||
writeStringJSONValue(&b, string(m))
|
||||
WriteStringJSONValue(&b, string(m))
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
@ -728,17 +728,17 @@ func (s *Source) UnmarshalJSON(data []byte) error {
|
|||
func (s Source) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
empty := true
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
if len(s.MediaType) > 0 {
|
||||
if v, err := s.MediaType.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
empty = !writeJSONProp(&b, "mediaType", v)
|
||||
empty = !WriteJSONProp(&b, "mediaType", v)
|
||||
}
|
||||
}
|
||||
if len(s.Content) > 0 {
|
||||
empty = !writeNaturalLanguageJSONProp(&b, "content", s.Content)
|
||||
empty = !WriteNaturalLanguageJSONProp(&b, "content", s.Content)
|
||||
}
|
||||
if !empty {
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
|
|
@ -221,34 +221,34 @@ func (o *OrderedCollection) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadOrderedCollection(val, o)
|
||||
return LoadOrderedCollection(val, o)
|
||||
}
|
||||
|
||||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (o OrderedCollection) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
notEmpty := false
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
OnObject(o, func(o *Object) error {
|
||||
notEmpty = writeObjectJSONValue(&b, *o)
|
||||
notEmpty = WriteObjectJSONValue(&b, *o)
|
||||
return nil
|
||||
})
|
||||
if o.Current != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "current", o.Current) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "current", o.Current) || notEmpty
|
||||
}
|
||||
if o.First != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "first", o.First) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "first", o.First) || notEmpty
|
||||
}
|
||||
if o.Last != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "last", o.Last) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "last", o.Last) || notEmpty
|
||||
}
|
||||
notEmpty = writeIntJSONProp(&b, "totalItems", int64(o.TotalItems)) || notEmpty
|
||||
notEmpty = WriteIntJSONProp(&b, "totalItems", int64(o.TotalItems)) || notEmpty
|
||||
if o.OrderedItems != nil {
|
||||
notEmpty = writeItemCollectionJSONProp(&b, "orderedItems", o.OrderedItems) || notEmpty
|
||||
notEmpty = WriteItemCollectionJSONProp(&b, "orderedItems", o.OrderedItems) || notEmpty
|
||||
}
|
||||
if notEmpty {
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
|
|
@ -198,43 +198,43 @@ func (o *OrderedCollectionPage) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadOrderedCollectionPage(val, o)
|
||||
return LoadOrderedCollectionPage(val, o)
|
||||
}
|
||||
|
||||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (o OrderedCollectionPage) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
notEmpty := false
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
OnObject(o, func(o *Object) error {
|
||||
notEmpty = writeObjectJSONValue(&b, *o)
|
||||
notEmpty = WriteObjectJSONValue(&b, *o)
|
||||
return nil
|
||||
})
|
||||
if o.PartOf != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "partOf", o.PartOf) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "partOf", o.PartOf) || notEmpty
|
||||
}
|
||||
if o.Current != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "current", o.Current) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "current", o.Current) || notEmpty
|
||||
}
|
||||
if o.First != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "first", o.First) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "first", o.First) || notEmpty
|
||||
}
|
||||
if o.Last != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "last", o.Last) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "last", o.Last) || notEmpty
|
||||
}
|
||||
if o.Next != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "next", o.Next) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "next", o.Next) || notEmpty
|
||||
}
|
||||
if o.Prev != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "prev", o.Prev) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "prev", o.Prev) || notEmpty
|
||||
}
|
||||
notEmpty = writeIntJSONProp(&b, "totalItems", int64(o.TotalItems)) || notEmpty
|
||||
notEmpty = WriteIntJSONProp(&b, "totalItems", int64(o.TotalItems)) || notEmpty
|
||||
if o.OrderedItems != nil {
|
||||
notEmpty = writeItemCollectionJSONProp(&b, "orderedItems", o.OrderedItems) || notEmpty
|
||||
notEmpty = WriteItemCollectionJSONProp(&b, "orderedItems", o.OrderedItems) || notEmpty
|
||||
}
|
||||
if notEmpty {
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
|
20
place.go
20
place.go
|
@ -163,39 +163,39 @@ func (p *Place) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadPlace(val, p)
|
||||
return LoadPlace(val, p)
|
||||
}
|
||||
|
||||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (p Place) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
notEmpty := false
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
OnObject(p, func(o *Object) error {
|
||||
notEmpty = writeObjectJSONValue(&b, *o)
|
||||
notEmpty = WriteObjectJSONValue(&b, *o)
|
||||
return nil
|
||||
})
|
||||
if p.Accuracy > 0 {
|
||||
notEmpty = writeFloatJSONProp(&b, "accuracy", p.Accuracy) || notEmpty
|
||||
notEmpty = WriteFloatJSONProp(&b, "accuracy", p.Accuracy) || notEmpty
|
||||
}
|
||||
if p.Altitude > 0 {
|
||||
notEmpty = writeFloatJSONProp(&b, "altitude", p.Altitude) || notEmpty
|
||||
notEmpty = WriteFloatJSONProp(&b, "altitude", p.Altitude) || notEmpty
|
||||
}
|
||||
if p.Latitude > 0 {
|
||||
notEmpty = writeFloatJSONProp(&b, "latitude", p.Latitude) || notEmpty
|
||||
notEmpty = WriteFloatJSONProp(&b, "latitude", p.Latitude) || notEmpty
|
||||
}
|
||||
if p.Longitude > 0 {
|
||||
notEmpty = writeFloatJSONProp(&b, "longitude", p.Longitude) || notEmpty
|
||||
notEmpty = WriteFloatJSONProp(&b, "longitude", p.Longitude) || notEmpty
|
||||
}
|
||||
if p.Radius > 0 {
|
||||
notEmpty = writeIntJSONProp(&b, "radius", p.Radius) || notEmpty
|
||||
notEmpty = WriteIntJSONProp(&b, "radius", p.Radius) || notEmpty
|
||||
}
|
||||
if len(p.Units) > 0 {
|
||||
notEmpty = writeStringJSONProp(&b, "radius", p.Units) || notEmpty
|
||||
notEmpty = WriteStringJSONProp(&b, "radius", p.Units) || notEmpty
|
||||
}
|
||||
if notEmpty {
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
|
|
@ -149,25 +149,25 @@ func (p *Profile) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadProfile(val, p)
|
||||
return LoadProfile(val, p)
|
||||
}
|
||||
|
||||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (p Profile) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
notEmpty := false
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
OnObject(p, func(o *Object) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
if p.Describes != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "describes", p.Describes) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "describes", p.Describes) || notEmpty
|
||||
}
|
||||
|
||||
if notEmpty {
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
|
|
@ -174,18 +174,18 @@ func (q *Question) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadQuestion(val, q)
|
||||
return LoadQuestion(val, q)
|
||||
}
|
||||
|
||||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (q Question) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
if !writeQuestionJSONValue(&b, q) {
|
||||
if !WriteQuestionJSONValue(&b, q) {
|
||||
return nil, nil
|
||||
}
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -159,32 +159,32 @@ func (r *Relationship) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadRelationship(val, r)
|
||||
return LoadRelationship(val, r)
|
||||
}
|
||||
|
||||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (r Relationship) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
notEmpty := false
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
OnObject(r, func(o *Object) error {
|
||||
notEmpty = writeObjectJSONValue(&b, *o)
|
||||
notEmpty = WriteObjectJSONValue(&b, *o)
|
||||
return nil
|
||||
})
|
||||
|
||||
if r.Subject != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "subject", r.Subject) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "subject", r.Subject) || notEmpty
|
||||
}
|
||||
if r.Object != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "object", r.Object) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "object", r.Object) || notEmpty
|
||||
}
|
||||
if r.Relationship != nil {
|
||||
notEmpty = writeItemJSONProp(&b, "relationship", r.Relationship) || notEmpty
|
||||
notEmpty = WriteItemJSONProp(&b, "relationship", r.Relationship) || notEmpty
|
||||
}
|
||||
|
||||
if notEmpty {
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
|
12
tombstone.go
12
tombstone.go
|
@ -151,29 +151,29 @@ func (t *Tombstone) UnmarshalJSON(data []byte) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return loadTombstone(val, t)
|
||||
return LoadTombstone(val, t)
|
||||
}
|
||||
|
||||
// MarshalJSON encodes the receiver object to a JSON document.
|
||||
func (t Tombstone) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0)
|
||||
notEmpty := false
|
||||
write(&b, '{')
|
||||
Write(&b, '{')
|
||||
|
||||
OnObject(t, func(o *Object) error {
|
||||
notEmpty = writeObjectJSONValue(&b, *o)
|
||||
notEmpty = WriteObjectJSONValue(&b, *o)
|
||||
return nil
|
||||
})
|
||||
if len(t.FormerType) > 0 {
|
||||
if v, err := t.FormerType.MarshalJSON(); err == nil && len(v) > 0 {
|
||||
notEmpty = writeJSONProp(&b, "formerType", v) || notEmpty
|
||||
notEmpty = WriteJSONProp(&b, "formerType", v) || notEmpty
|
||||
}
|
||||
}
|
||||
if !t.Deleted.IsZero() {
|
||||
notEmpty = writeTimeJSONProp(&b, "deleted", t.Deleted) || notEmpty
|
||||
notEmpty = WriteTimeJSONProp(&b, "deleted", t.Deleted) || notEmpty
|
||||
}
|
||||
if notEmpty {
|
||||
write(&b, '}')
|
||||
Write(&b, '}')
|
||||
return b, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
|
Reference in a new issue