goap/baseInterface.go
Melody 2f74543ca1 Meow
- No more BaseObject with Id and Type included, moved those into the
nsUndefined namespace
- Refactored the full parser funcs into two slightly distinct ones:
  - One that takes in raw bytes and one that takes in a map[string]any
2024-08-28 19:14:23 +02:00

27 lines
1 KiB
Go

package goap
// Interface for every struct that can be part of an ActivityPub object
type BaseApChain interface {
// Get the next "object" in the chain (or self if last element in chain)
// Though preferably the last element should always be a BaseObject
// The 2nd parameter indicates whether the returned value is different from the one the function is called on
// So true => Is a different object, false => is self
GetSelfOrBase() (BaseApChain, bool)
// Convert the chain to a map
// Should include the rest of the chain (extend the map the underlying object returns)
MarshalToMap() map[string]any
}
// Func used to add parsers for other attributes not yet included in the library
// It is expected that, on success, the function removes its key from the raw map
type UnmarshalFunc func(map[string]any, BaseApChain) (BaseApChain, error)
type EmptyBaseObject struct{}
func (e *EmptyBaseObject) GetSelfOrBase() (BaseApChain, bool) {
return e, false
}
func (e *EmptyBaseObject) MarshalToMap() map[string]any {
return map[string]any{}
}