registry

package
v0.0.0-...-c92cbe1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

Struct name to Type registry

Overview

Unfortunetaly, Golang does not have a name -> type registry built in, e.g. you cannot instantiate a struct based on its name only. This limits a component performing a generic task, while being agnostic to the data type it handles.

The Resitry

The registry is a simple name->type repository that is able to instantiate a struct based on its type name via the reflect package.

Usage

//Register a struct type via an instance of this struct
common.Registry.RegisterStruct(<a struct instance>)
//Instantiate a new struct instance
//v := common.Registry.NewInstance("my stuct name").(<cast to the type)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StructRegistryImpl

type StructRegistryImpl struct {
	// contains filtered or unexported fields
}

func NewStructRegistry

func NewStructRegistry() *StructRegistryImpl

func (*StructRegistryImpl) NewInstance

func (r *StructRegistryImpl) NewInstance(name string) (interface{}, error)

func (*StructRegistryImpl) NewProtobufInstance

func (r *StructRegistryImpl) NewProtobufInstance(t string) (proto.Message, error)

func (*StructRegistryImpl) RegisterStruct

func (r *StructRegistryImpl) RegisterStruct(any interface{}) bool

func (*StructRegistryImpl) RegisterStructType

func (r *StructRegistryImpl) RegisterStructType(t reflect.Type) bool

func (*StructRegistryImpl) TypeByName

func (r *StructRegistryImpl) TypeByName(name string) (reflect.Type, error)

Jump to

Keyboard shortcuts

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