Sorted constants a little ActivityStreams stuff now have their own BaseApChain types
77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package goap
|
|
|
|
import "maps"
|
|
|
|
type PublicKey struct {
|
|
Id string
|
|
Owner string
|
|
Pem string
|
|
}
|
|
|
|
type Attachment struct {
|
|
Type string
|
|
Value string
|
|
Name string
|
|
}
|
|
|
|
type Media struct {
|
|
Type string
|
|
MediaType *string
|
|
Url string
|
|
Sensitive *bool
|
|
}
|
|
|
|
type IdValue struct {
|
|
Id string
|
|
}
|
|
|
|
type ValueValue[T any] struct {
|
|
Type *string
|
|
Value T
|
|
OtherThings map[string]any
|
|
}
|
|
|
|
func (p PublicKey) Marshal() map[string]any {
|
|
return map[string]any{
|
|
KEY_ID: p.Id,
|
|
KEY_W3_SECURITY_OWNER: IdValue{Id: p.Owner}.Marshal(),
|
|
}
|
|
}
|
|
|
|
func (a Attachment) Marshal() map[string]any {
|
|
return map[string]any{
|
|
KEY_TYPE: []string{KEY_SCHEMA_PROPERTYVALUE},
|
|
KEY_SCHEMA_VALUE: []map[string]any{ValueValue[string]{Value: a.Value}.Marshal()},
|
|
KEY_ACTIVITYSTREAMS_NAME: []map[string]any{ValueValue[string]{Value: a.Name}.Marshal()},
|
|
}
|
|
}
|
|
|
|
func (i IdValue) Marshal() map[string]any {
|
|
return map[string]any{
|
|
KEY_ID: i.Id,
|
|
}
|
|
}
|
|
|
|
func (v ValueValue[T]) Marshal() map[string]any {
|
|
m := maps.Clone(v.OtherThings)
|
|
m[KEY_VALUE] = v.Value
|
|
if v.Type != nil {
|
|
m[KEY_TYPE] = *v.Type
|
|
}
|
|
return m
|
|
}
|
|
|
|
func (m Media) Marshal() map[string]any {
|
|
t := map[string]any{
|
|
KEY_TYPE: []string{m.Type},
|
|
KEY_ACTIVITYSTREAMS_URL: []map[string]any{IdValue{Id: m.Url}.Marshal()},
|
|
}
|
|
if m.MediaType != nil {
|
|
t[KEY_ACTIVITYSTREAMS_MEDIATYPE] = []map[string]any{{KEY_VALUE: *m.MediaType}}
|
|
}
|
|
if m.Sensitive != nil {
|
|
t[KEY_ACTIVITYSTREAMS_SENSITIVE] = []map[string]any{{KEY_VALUE: *m.Sensitive}}
|
|
}
|
|
|
|
return t
|
|
}
|