Documentation ¶
Index ¶
- Variables
- func GetKey(x proto.Message) (string, error)
- func GetKeyForItem(item *api.Item) (string, error)
- func GetName(x proto.Message) (string, error)
- func Key(x proto.Message) string
- func MarshalItem(pb proto.Message) (*api.Item, error)
- func Name(x proto.Message) string
- func UnmarshalItem(item *api.Item) (proto.Message, error)
- type KnownModel
- func GetModel(name string) (KnownModel, error)
- func GetModelFor(x proto.Message) (KnownModel, error)
- func GetModelForItem(item *api.Item) (KnownModel, error)
- func GetModelForKey(key string) (KnownModel, error)
- func Register(pb proto.Message, spec Spec, opts ...ModelOption) *KnownModel
- func RegisteredModels() []KnownModel
- func (m KnownModel) GoType() string
- func (m KnownModel) IsKeyValid(key string) bool
- func (m KnownModel) KeyPrefix() string
- func (m KnownModel) ModelDetail() *generic.ModelDetail
- func (m KnownModel) Name() string
- func (m KnownModel) NameTemplate() string
- func (m KnownModel) NewInstance() proto.Message
- func (m KnownModel) ParseKey(key string) (name string, valid bool)
- func (m KnownModel) ProtoName() string
- func (m KnownModel) Spec() *Spec
- func (m KnownModel) StripKeyPrefix(key string) string
- type ModelOption
- type NameFunc
- type Registry
- func (r *Registry) GetModel(name string) (KnownModel, error)
- func (r *Registry) GetModelFor(x interface{}) (KnownModel, error)
- func (r *Registry) GetModelForKey(key string) (KnownModel, error)
- func (r *Registry) Register(x interface{}, spec Spec, opts ...ModelOption) (*KnownModel, error)
- func (r *Registry) RegisteredModels() []KnownModel
- type Spec
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultRegistry represents a global registry for models. DefaultRegistry = NewRegistry() )
Functions ¶
func GetKey ¶
GetKey returns complete key for gived model, including key prefix defined by model specification. It returns error if given model is not registered.
func GetKeyForItem ¶
GetKeyForItem returns key for given item.
func MarshalItem ¶
Marshal is helper function for marshalling model instance into item.
Types ¶
type KnownModel ¶
type KnownModel struct {
// contains filtered or unexported fields
}
KnownModel represents a registered model.
func GetModel ¶
func GetModel(name string) (KnownModel, error)
GetModel returns registered model for given model name.
func GetModelFor ¶
func GetModelFor(x proto.Message) (KnownModel, error)
GetModelFor returns model registered in DefaultRegistry for given proto message.
func GetModelForItem ¶
func GetModelForItem(item *api.Item) (KnownModel, error)
GetModelForItem returns model for given item.
func GetModelForKey ¶
func GetModelForKey(key string) (KnownModel, error)
GetModelForKey returns model registered in DefaultRegistry which matches key.
func Register ¶
func Register(pb proto.Message, spec Spec, opts ...ModelOption) *KnownModel
Register registers model in DefaultRegistry.
func RegisteredModels ¶
func RegisteredModels() []KnownModel
RegisteredModels returns models registered in the DefaultRegistry.
func (KnownModel) GoType ¶
func (m KnownModel) GoType() string
GoType returns go type for the model.
func (KnownModel) IsKeyValid ¶
func (m KnownModel) IsKeyValid(key string) bool
IsKeyValid returns true if given key is valid for this model.
func (KnownModel) KeyPrefix ¶
func (m KnownModel) KeyPrefix() string
KeyPrefix returns key prefix for the model.
func (KnownModel) ModelDetail ¶
func (m KnownModel) ModelDetail() *generic.ModelDetail
ModelDescriptor returns descriptor for the model.
func (KnownModel) NameTemplate ¶
func (m KnownModel) NameTemplate() string
NameTemplate returns name template for the model.
func (KnownModel) NewInstance ¶
func (m KnownModel) NewInstance() proto.Message
NewInstance creates new instance value for model type.
func (KnownModel) ParseKey ¶
func (m KnownModel) ParseKey(key string) (name string, valid bool)
ParseKey parses the given key and returns item name or returns empty name and valid as false if the key is not valid.
func (KnownModel) ProtoName ¶
func (m KnownModel) ProtoName() string
ProtoName returns proto message name registered with the model.
func (KnownModel) Spec ¶
func (m KnownModel) Spec() *Spec
Spec returns model specification for the model.
func (KnownModel) StripKeyPrefix ¶
func (m KnownModel) StripKeyPrefix(key string) string
StripKeyPrefix returns key with prefix stripped.
type ModelOption ¶
type ModelOption func(*modelOptions)
ModelOption defines function type which sets model options.
func WithNameTemplate ¶
func WithNameTemplate(t string) ModelOption
WithNameTemplate returns option for models which sets function for generating name of instances using custom template.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry defines model registry for managing registered models.
func (*Registry) GetModel ¶
func (r *Registry) GetModel(name string) (KnownModel, error)
GetModel returns registered model for the given model name or error if model is not found.
func (*Registry) GetModelFor ¶
func (r *Registry) GetModelFor(x interface{}) (KnownModel, error)
GetModelFor returns registered model for the given proto message.
func (*Registry) GetModelForKey ¶
func (r *Registry) GetModelForKey(key string) (KnownModel, error)
GetModelForKey returns registered model for the given key or error.
func (*Registry) Register ¶
func (r *Registry) Register(x interface{}, spec Spec, opts ...ModelOption) (*KnownModel, error)
Register registers a protobuf message with given model specification. If spec.Class is unset empty it defaults to 'config'.
func (*Registry) RegisteredModels ¶
func (r *Registry) RegisteredModels() []KnownModel
RegisteredModels returns all registered modules.