Documentation
¶
Index ¶
- func Unmarshal[T any](payload []byte) (object T, err error)
- type PropertyRegistry
- func (registry *PropertyRegistry[T]) Add(classes ...core.TypeCarrier) *PropertyRegistry[T]
- func (registry *PropertyRegistry[T]) Append(classes ...core.TypeCarrier) *PropertyRegistry[T]
- func (registry PropertyRegistry[T]) Length() int
- func (registry PropertyRegistry[T]) Size() int
- func (registry PropertyRegistry[T]) Unmarshal(payload []byte) (object T, err error)
- type SyncPropertyRegistry
- func (registry *SyncPropertyRegistry[T]) Add(classes ...core.TypeCarrier) *SyncPropertyRegistry[T]
- func (registry *SyncPropertyRegistry[T]) Append(classes ...core.TypeCarrier) *SyncPropertyRegistry[T]
- func (registry *SyncPropertyRegistry[T]) Length() int
- func (registry *SyncPropertyRegistry[T]) Size() int
- func (registry *SyncPropertyRegistry[T]) Unmarshal(payload []byte) (object T, err error)
- type SyncTypeRegistry
- func (registry *SyncTypeRegistry[T]) Add(classes ...core.TypeCarrier) *SyncTypeRegistry[T]
- func (registry *SyncTypeRegistry[T]) AddTypeTag(tag string) *SyncTypeRegistry[T]
- func (registry *SyncTypeRegistry[T]) AddTypeTags(tags ...string) *SyncTypeRegistry[T]
- func (registry *SyncTypeRegistry[T]) Append(classes ...core.TypeCarrier) *SyncTypeRegistry[T]
- func (registry *SyncTypeRegistry[T]) Length() int
- func (registry *SyncTypeRegistry[T]) Size() int
- func (registry *SyncTypeRegistry[T]) Unmarshal(payload []byte) (object T, err error)
- type TypeRegistry
- func (registry *TypeRegistry[T]) Add(classes ...core.TypeCarrier) *TypeRegistry[T]
- func (registry *TypeRegistry[T]) AddTypeTag(tag string) *TypeRegistry[T]
- func (registry *TypeRegistry[T]) AddTypeTags(tags ...string) *TypeRegistry[T]
- func (registry *TypeRegistry[T]) Append(classes ...core.TypeCarrier) *TypeRegistry[T]
- func (registry TypeRegistry[T]) Length() int
- func (registry TypeRegistry[T]) Size() int
- func (registry TypeRegistry[T]) Unmarshal(payload []byte) (object T, err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PropertyRegistry ¶
type PropertyRegistry[T core.TypeCarrier] struct { // contains filtered or unexported fields }
PropertyRegistry contains a map of identifier vs Type
A PropertyRegistry is used to unmarshal payloads that use a property to identify the TypeCarrier.
PropertyRegistry is not thread safe.
func NewPropertyRegistry ¶
func NewPropertyRegistry[T core.TypeCarrier](tags ...string) *PropertyRegistry[T]
NewPropertyRegistry creates a new PropertyRegistry
func (*PropertyRegistry[T]) Add ¶
func (registry *PropertyRegistry[T]) Add(classes ...core.TypeCarrier) *PropertyRegistry[T]
Add adds one or more TypeCarriers to the PropertyRegistry
func (*PropertyRegistry[T]) Append ¶
func (registry *PropertyRegistry[T]) Append(classes ...core.TypeCarrier) *PropertyRegistry[T]
Append adds one or more TypeCarriers to the PropertyRegistry
This is a synonym for Add
func (PropertyRegistry[T]) Length ¶
func (registry PropertyRegistry[T]) Length() int
Length returns the number of TypeCarriers in the TypeRegistry
func (PropertyRegistry[T]) Size ¶
func (registry PropertyRegistry[T]) Size() int
Size returns the number of TypeCarriers in the TypeRegistry
func (PropertyRegistry[T]) Unmarshal ¶
func (registry PropertyRegistry[T]) Unmarshal(payload []byte) (object T, err error)
Unmarshal unmarshal a payload into a Type Carrier
The interface that is returned contains a pointer to the TypeCarrier structure.
Examples:
object, err := registry.Unmarshal(payload)
Example ¶
registry := argo.NewPropertyRegistry[Something]().Add(Something1{}, Something2{})
object, err := registry.Unmarshal([]byte(`{"something2":{"data":"data"}}`))
if err != nil {
fmt.Println(err)
}
something2, ok := object.(*Something2)
if !ok {
fmt.Println("Object is not a Something2")
return
}
fmt.Println(something2.Data)
Output: data
type SyncPropertyRegistry ¶
type SyncPropertyRegistry[T core.TypeCarrier] struct { // contains filtered or unexported fields }
SyncPropertyRegistry contains a map of identifier vs Type
A SyncPropertyRegistry is used to unmarshal payloads that use a property to identify the TypeCarrier.
SyncPropertyRegistry is thread safe.
func NewSyncPropertyRegistry ¶
func NewSyncPropertyRegistry[T core.TypeCarrier](tags ...string) *SyncPropertyRegistry[T]
NewSyncPropertyRegistry creates a new SyncPropertyRegistry
func (*SyncPropertyRegistry[T]) Add ¶
func (registry *SyncPropertyRegistry[T]) Add(classes ...core.TypeCarrier) *SyncPropertyRegistry[T]
Add adds one or more TypeCarriers to the SyncPropertyRegistry
func (*SyncPropertyRegistry[T]) Append ¶
func (registry *SyncPropertyRegistry[T]) Append(classes ...core.TypeCarrier) *SyncPropertyRegistry[T]
Append adds one or more TypeCarriers to the SyncPropertyRegistry
This is a synonym for Add
func (*SyncPropertyRegistry[T]) Length ¶
func (registry *SyncPropertyRegistry[T]) Length() int
Length returns the number of TypeCarriers in the TypeRegistry
func (*SyncPropertyRegistry[T]) Size ¶
func (registry *SyncPropertyRegistry[T]) Size() int
Size returns the number of TypeCarriers in the TypeRegistry
func (*SyncPropertyRegistry[T]) Unmarshal ¶
func (registry *SyncPropertyRegistry[T]) Unmarshal(payload []byte) (object T, err error)
Unmarshal unmarshal a payload into a Type Carrier
The interface that is returned contains a pointer to the TypeCarrier structure.
Examples:
object, err := registry.Unmarshal(payload)
Example ¶
registry := argo.NewSyncPropertyRegistry[Something]().Add(Something1{}, Something2{})
object, err := registry.Unmarshal([]byte(`{"something2":{"data":"data"}}`))
if err != nil {
fmt.Println(err)
}
something2, ok := object.(*Something2)
if !ok {
fmt.Println("Object is not a Something2")
return
}
fmt.Println(something2.Data)
Output: data
type SyncTypeRegistry ¶
type SyncTypeRegistry[T core.TypeCarrier] struct { // contains filtered or unexported fields }
SyncTypeRegistry contains a map of identifier vs Type
A SyncTypeRegistry is used to unmarshal payloads with core.TypeCarriers.
SyncTypeRegistry is thread safe.
func NewSyncTypeRegistry ¶
func NewSyncTypeRegistry[T core.TypeCarrier](tags ...string) *SyncTypeRegistry[T]
NewSyncTypeRegistry creates a new TypeRegistry
func (*SyncTypeRegistry[T]) Add ¶
func (registry *SyncTypeRegistry[T]) Add(classes ...core.TypeCarrier) *SyncTypeRegistry[T]
Add adds one or more TypeCarriers to the SyncTypeRegistry
func (*SyncTypeRegistry[T]) AddTypeTag ¶
func (registry *SyncTypeRegistry[T]) AddTypeTag(tag string) *SyncTypeRegistry[T]
AddType adds a Type Tag to the SyncTypeRegistry
func (*SyncTypeRegistry[T]) AddTypeTags ¶
func (registry *SyncTypeRegistry[T]) AddTypeTags(tags ...string) *SyncTypeRegistry[T]
AddTypeTags adds one or more Type Tags to the SyncTypeRegistry
func (*SyncTypeRegistry[T]) Append ¶
func (registry *SyncTypeRegistry[T]) Append(classes ...core.TypeCarrier) *SyncTypeRegistry[T]
Append adds one or more TypeCarriers to the SyncTypeRegistry
This is a synonym for Add
func (*SyncTypeRegistry[T]) Length ¶
func (registry *SyncTypeRegistry[T]) Length() int
Length returns the number of TypeCarriers in the SyncTypeRegistry
func (*SyncTypeRegistry[T]) Size ¶
func (registry *SyncTypeRegistry[T]) Size() int
Size returns the number of TypeCarriers in the SyncTypeRegistry
func (*SyncTypeRegistry[T]) Unmarshal ¶
func (registry *SyncTypeRegistry[T]) Unmarshal(payload []byte) (object T, err error)
Unmarshal unmarshal a payload into a Type Carrier
The interface that is returned contains a pointer to the TypeCarrier structure.
if the SyncTypeRegistry has no Type Tags, "type" will be used.
Example ¶
***************************************************************************** Suite Tests
// Typically, each struct would be declared in its own go file
// and the argo.TypeRegistry.Add() func would be done in the init() func of each file
registry := argo.NewSyncTypeRegistry[Something]().Add(Something1{}, Something2{})
object, err := registry.Unmarshal([]byte(`{"type": "something1", "data": "data"}`))
if err != nil {
fmt.Println(err)
return
}
something1, ok := object.(*Something1)
if !ok {
fmt.Println("Object is not a Something1")
return
}
fmt.Println(something1.Data)
Output: data
Example (WithTypeTag) ¶
// Typically, each struct would be declared in its own go file
// and the argo.TypeRegistry.Add() func would be done in the init() func of each file
registry := argo.NewSyncTypeRegistry[Something]("__type").Add(Something1{}, Something2{})
object, err := registry.Unmarshal([]byte(`{"__type": "something1", "data": "data"}`))
if err != nil {
fmt.Println(err)
}
something1, ok := object.(*Something1)
if !ok {
fmt.Println("Object is not a Something1")
return
}
fmt.Println(something1.Data)
Output: data
type TypeRegistry ¶
type TypeRegistry[T core.TypeCarrier] struct { // contains filtered or unexported fields }
TypeRegistry contains a map of identifier vs Type
A TypeRegistry is used to unmarshal payloads with core.TypeCarriers.
TypeRegistry is not thread safe.
func NewTypeRegistry ¶
func NewTypeRegistry[T core.TypeCarrier](tags ...string) *TypeRegistry[T]
NewTypeRegistry creates a new TypeRegistry
func (*TypeRegistry[T]) Add ¶
func (registry *TypeRegistry[T]) Add(classes ...core.TypeCarrier) *TypeRegistry[T]
Add adds one or more TypeCarriers to the TypeRegistry
func (*TypeRegistry[T]) AddTypeTag ¶
func (registry *TypeRegistry[T]) AddTypeTag(tag string) *TypeRegistry[T]
AddType adds a Type Tag to the TypeRegistry
func (*TypeRegistry[T]) AddTypeTags ¶
func (registry *TypeRegistry[T]) AddTypeTags(tags ...string) *TypeRegistry[T]
AddTypeTags adds one or more Type Tags to the TypeRegistry
func (*TypeRegistry[T]) Append ¶
func (registry *TypeRegistry[T]) Append(classes ...core.TypeCarrier) *TypeRegistry[T]
Append adds one or more TypeCarriers to the TypeRegistry
This is a synonym for Add
func (TypeRegistry[T]) Length ¶
func (registry TypeRegistry[T]) Length() int
Length returns the number of TypeCarriers in the TypeRegistry
func (TypeRegistry[T]) Size ¶
func (registry TypeRegistry[T]) Size() int
Size returns the number of TypeCarriers in the TypeRegistry
func (TypeRegistry[T]) Unmarshal ¶
func (registry TypeRegistry[T]) Unmarshal(payload []byte) (object T, err error)
Unmarshal unmarshal a payload into a Type Carrier
The interface that is returned contains a pointer to the TypeCarrier structure.
if the TypeRegistry has no Type Tags, "type" will be used.
Example ¶
***************************************************************************** Suite Tests
// Typically, each struct would be declared in its own go file
// and the argo.TypeRegistry.Add() func would be done in the init() func of each file
registry := argo.NewTypeRegistry[Something]().Add(Something1{}, Something2{})
object, err := registry.Unmarshal([]byte(`{"type": "something1", "data": "data"}`))
if err != nil {
fmt.Println(err)
return
}
something1, ok := object.(*Something1)
if !ok {
fmt.Println("Object is not a Something1")
return
}
fmt.Println(something1.Data)
Output: data
Example (WithTypeTag) ¶
// Typically, each struct would be declared in its own go file
// and the argo.TypeRegistry.Add() func would be done in the init() func of each file
registry := argo.NewTypeRegistry[Something]("__type").Add(Something1{}, Something2{})
object, err := registry.Unmarshal([]byte(`{"__type": "something1", "data": "data"}`))
if err != nil {
fmt.Println(err)
}
something1, ok := object.(*Something1)
if !ok {
fmt.Println("Object is not a Something1")
return
}
fmt.Println(something1.Data)
Output: data