-
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
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
package activitypub
import (
"github.com/buger/jsonparser"
as "github.com/go-ap/activitystreams"
)
func JSONGetItemByType(typ as.ActivityVocabularyType) (as.Item, error) {
var ret as.Item
var err error
switch typ {
case as.ObjectType:
o := &Object{}
o.Type = typ
ret = o
case as.ActorType:
o := &actor{}
o.Type = typ
ret = o
case as.ApplicationType:
a := &Application{}
a.Type = typ
ret = a
case as.GroupType:
g := &Group{}
g.Type = typ
ret = g
case as.OrganizationType:
o := &Organization{}
o.Type = typ
ret = o
case as.PersonType:
p := &Person{}
p.Type = typ
ret = p
case as.ServiceType:
s := &Service{}
s.Type = typ
ret = s
case "":
// when no type is available use a plain Object
ret = &Object{}
default:
return as.JSONGetItemByType(typ)
}
return ret, err
}
func JSONGetActorEndpoints(data []byte, prop string) *Endpoints {
str, _ := jsonparser.GetUnsafeString(data, prop)
var e *Endpoints
if len(str) > 0 {
e = &Endpoints{}
e.UnmarshalJSON([]byte(str))
}
return e
}