-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
package activitypub
import (
"github.com/buger/jsonparser"
as "github.com/go-ap/activitystreams"
)
// Source is intended to convey some sort of source from which the content markup was derived,
// as a form of provenance, or to support future editing by clients.
type Source struct {
// Content
Content as.NaturalLanguageValue `jsonld:"content"`
// MediaType
MediaType as.MimeType `jsonld:"mediaType"`
}
// Object
type Object struct {
as.Object
// Source property is intended to convey some sort of source from which the content markup was derived,
// as a form of provenance, or to support future editing by clients.
// In general, clients do the conversion from source to content, not the other way around.
Source Source `jsonld:"source,omitempty"`
}
// GetAPSource
func GetAPSource(data []byte) Source {
s := Source{}
if contBytes, _, _, err := jsonparser.Get(data, "source", "content"); err == nil {
s.Content.UnmarshalJSON(contBytes)
}
if mimeBytes, _, _, err := jsonparser.Get(data, "source", "mediaType"); err == nil {
s.MediaType.UnmarshalJSON(mimeBytes)
}
return s
}
// UnmarshalJSON
func (s *Source) UnmarshalJSON(data []byte) error {
*s = GetAPSource(data)
return nil
}
// UnmarshalJSON
func (o *Object) UnmarshalJSON(data []byte) error {
o.Object.UnmarshalJSON(data)
o.Source = GetAPSource(data)
return nil
}