argo

package module
v0.0.0-...-5e803f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal[T any](payload []byte) (object T, err error)

Unmarshal unmarshals the payload into a generic type

Example
object, err := argo.Unmarshal[Something1]([]byte(`{"data": "data"}`))
if err != nil {
	return
}
fmt.Println(object.Data)
Output:
data

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 {
	Typetags []string
	// 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 {
	Typetags []string
	// 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址