models

package
v2.2.0-beta+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2019 License: Apache-2.0 Imports: 12 Imported by: 371

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetKey

func GetKey(x proto.Message) (string, error)

GetKey returns complete key for gived model, including key prefix defined by model specification. It returns error if given model is not registered.

func GetModel

func GetModel(x proto.Message) (registeredModel, error)

GetModel returns registered model for the given proto message.

func GetModelForKey

func GetModelForKey(key string) (registeredModel, error)

GetModelForKey returns registered model for the given key or error.

func GetName

func GetName(x proto.Message) (string, error)

GetName

func GetPath

func GetPath(x proto.Message) (string, error)

GetKeyPrefix returns key prefix for gived model. It returns error if given model is not registered.

func ItemKey

func ItemKey(item *api.Item) (string, error)

func Key

func Key(x proto.Message) string

Key is a shorthand for the GetKey for avoid error checking.

func MarshalItem

func MarshalItem(pb proto.Message) (*api.Item, error)

Marshal is helper function for marshalling items.

func Model

func Model(x proto.Message) registeredModel

Model returns registered model for the given proto message.

func ModelForItem

func ModelForItem(item *api.Item) (registeredModel, error)

ModelForItem

func Name

func Name(x proto.Message) string

Name is a shorthand for the GetName for avoid error checking.

func Path

func Path(x proto.Message) string

Path is a shorthand for the GetPath for avoid error checking.

func Register

func Register(pb proto.Message, spec Spec, opts ...ModelOption) *registeredModel

Register registers the protobuf message with given model specification.

func RegisteredModels

func RegisteredModels() (models []*api.ModelInfo)

RegisteredModels returns all registered modules.

func UnmarshalItem

func UnmarshalItem(m *api.Item) (proto.Message, error)

Unmarshal is helper function for unmarshalling items.

func UnmarshalLazyValue

func UnmarshalLazyValue(key string, lazy datasync.LazyValue) (proto.Message, error)

UnmarshalLazyValue is helper function for unmarshalling from datasync.LazyValue.

Types

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 NameFunc

type NameFunc func(obj interface{}) (string, error)

NameFunc represents function which can name model instance.

func NameTemplate

func NameTemplate(t string) NameFunc

type Spec

type Spec api.Model

Spec defines model specification used for registering model.

Jump to

Keyboard shortcuts

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