Categorygithub.com/ccmonky/typemap
modulepackage
0.5.0
Repository: https://github.com/ccmonky/typemap.git
Documentation: pkg.go.dev

# README

typemap

typemap contains a global TypeMap, which can be used to store various Types and their instances as resource registry.

Requirements

Usage

go get -u github.com/ccmonky/typemap
err := typemap.Register[*Demo](ctx, "first", &Demo{})
demo, err := typemap.Get[*Demo](ctx, "first")

# Functions

Clear clear T's instances cache if T not found, the default will be registered.
Delete delete a T instance specified by key if T not found, the default will be registered.
No description provided by the author
Get get instance of T from Type's instances cache.
No description provided by the author
GetAny get instance of T(specified by typeIdStr) from Type's instances cache.
No description provided by the author
GetAnyMany get multiple instances of T(specified by typeIdStr) from Type's instances cache.
No description provided by the author
GetMany get multiple instances of T from Type's instances cache.
GetType get *Type corresponding to T from global TypeMap.
GetTypeId return reflect type of T as TypeId.
GetTypeIdString return string representation of reflect type of T TODO: Uniqueness proof!.
No description provided by the author
MustClear clear T's instances cache, if error then panic.
MustDelete delete a T instance specified by key, if error then panic.
MustRegister register a T instance into Type's instances cache, if error then panic.
MustRegisterType Register T if error then panic.
MustSet set a T instance into Type's instances cache, if error then panic.
MustSetType Set T if error then panic.
New create a new T's instance, and New will indirect reflect.Ptr recursively to ensure not return nil pointer.
New instantiates a new cache entry.
NewConstructor return a constructor func which return a *Impl instance that implements interface Iface.
NewDefaultCache create a new default cache for type T - if T implements `Loadable`, returns a `cache.NewLoadable` with Load as LoadFunction - if T implements `DefaultLoader`, returns a `cache.NewLoadable` with LoadDefault as LoadFunction - if T implements `Default`, returns a `cache.NewLoadable` with Default as LoadFunction - otherwise, return a `cache.New`.
NewLoadable instanciates a new setter cache that uses a function to load data.
NewMap creates a new store to map (memory) library instance.
No description provided by the author
No description provided by the author
NewSyncMap creates a new store to sync.Map (memory) library instance.
Register register a T instance into Type's instances cache, if exists return error if T not found, the default will be registered.
RegisterType register a *Type into global TypeMap, if exists then try to update the exist *Type - can specify instances cache container with `WithInstancesCache`, which use `github.com/eko/gocache` interface default to `cache.New[T](NewMap())`, if tag cache exists then return already eixsts error - can specify T's dependencies(a slice of TypeId) with `WithDependencies`.
Set set a T instance into Type's instances cache, if exists then override it if T not found, the default will be registered.
SetAPI used to set type instances.
SetType register a *Type into global TypeMap, if exists then override it - can specify instances cache container with `WithInstancesCache`, which use `github.com/eko/gocache` interface default to `cache.New(NewMap())` - can specify T's dependencies(a slice of TypeId) with `WithDependencies`.
Types returns all Types.
No description provided by the author
WithDependencies control option to specify the T's dependencies, should be a slice of valid TypeId, used for sort.
WithDescription control option to specify the T's description.
WithInstancesCache control option to specify the T's instances cache.
WithStoreOption specify store.Option as Option.
WithTag specify the tag to get instance of T according tag.
WithTypeOption specify TypeOption as Option.

# Constants

CacheAnyType represents the setter cache any type as a string value.
DefaultUnmarshalTimeout timeout for custom unmarshal of Ref&Reg.
LoadableSetterCacheAnyType represents the loadable setter cache any type as a string value.
MapTagPattern represents the tag pattern to be used as a key in specified storage.
MapType represents the storage type as a string value.
NoExpiration for use with functions that take an expiration time.
SyncMapTagPattern represents the tag pattern to be used as a key in specified storage.
SyncMapType represents the storage type as a string value.

# Variables

No description provided by the author
No description provided by the author

# Structs

CacheAny represents a setter cache and implements SetterAnyCacheInterface.
CacheInfo auxiliary json serialization.
No description provided by the author
No description provided by the author
LoadableSetterCacheAny represents a setter cache that uses a function to load data, and implements `SetterAnyCacheInterface`.
MapStore is a store for map (memory) library.
No description provided by the author
Options control options for TypeMap's instances api, Register|Set|Get|Delete|Clear.
Ref used as a reference field that will refer to a T instance stored in typemap usage: type Demo struct { AFunc Ref[func()string] `json:"afunc"` } // 1.
Reg used as a field that will set its name & value into instances map of T in typemap.
SyncMapStore is a store for sync.Map (memory) library.
No description provided by the author
TypeMap a map[TypeId]*Type, with type meta info and instances in *Type.
TypeOptions options used to control Type creation.

# Interfaces

Default giving a type a useful default value.
DefaultLoader load default instance of T according to key.
Dependencies describes the type's dependencies.
Description giving a type a description.
No description provided by the author
Loadable load instance of T according to key.
Registerable used for `map` and `syncmap` cache to support `Register`, that is set if not exist.
SetterCacheAnyInterface.

# Type aliases

Action used to how to act(register or set?) on instance of Reg.
Option control option for instances api, Register|Set|Get|Delete|Clear.
Options control option func for TypeMap's type api, RegisterType|SetType.