controller

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package controller contains root neuron structure. It is responsible for getting access to registered models and their repositories. It contains the configuration, validators and default query processor.

Index

Constants

This section is empty.

Variables

View Source
var (
	// MjrController defines major classification for the controller.
	MjrController errors.Major
	// MnrRepository defines minor for repositories.
	MnrRepository errors.Minor
	// ClassRepositoryNotFound defines error classification.
	ClassRepositoryNotFound errors.Class
	// ClassRepositoryAlreadyRegistered class of errors when repository is already registered.
	ClassRepositoryAlreadyRegistered errors.Class

	// MnrConfig defines the error classification related with the config.
	MnrConfig errors.Minor
	// ClassInvalidConfig provided invalid or nil config.
	ClassInvalidConfig errors.Class
	// ClassInvalidModel is the error classification for the invalid input models.
	ClassInvalidModel errors.Class
)

Functions

func CloseAll added in v0.15.0

func CloseAll(ctx context.Context) error

CloseAll gently closes repository connections.

func DialAll added in v0.15.0

func DialAll(ctx context.Context) error

DialAll establish connections for all repositories.

func GetRepository added in v0.15.0

func GetRepository(model interface{}) (repository.Repository, error)

GetRepository gets 'model' repository.

func HealthCheck added in v0.15.0

func HealthCheck(ctx context.Context) (*repository.HealthResponse, error)

HealthCheck checks all repositories health.

func MigrateModels added in v0.15.0

func MigrateModels(ctx context.Context, models ...interface{}) error

MigrateModels updates or creates provided models representation in their related repositories. A representation of model might be a database table, collection etc. Model's repository must implement repository.Migrator.

func ModelStruct added in v0.15.0

func ModelStruct(model interface{}) (*mapping.ModelStruct, error)

ModelStruct gets the model struct on the base of the provided model

func MustModelStruct added in v0.15.0

func MustModelStruct(model interface{}) *mapping.ModelStruct

MustModelStruct gets the model struct from the cached model Map. Panics if the model does not exists in the map.

func MustNew added in v0.15.0

func MustNew(cfg *config.Controller)

MustNew creates new controller for given config 'cfg'. On error panics.

func New

func New(cfg *config.Controller) (err error)

New creates new controller for given config 'cfg'.

func Now added in v0.15.0

func Now() time.Time

Now gets and returns current timestamp. If the configs specify the function might return UTC timestamp.

func RegisterModels added in v0.15.0

func RegisterModels(models ...interface{}) (err error)

RegisterModels registers provided models within the context of the provided Controller. All repositories must be registered up to this moment.

func RegisterRepository added in v0.15.0

func RegisterRepository(name string, cfg *config.Repository) (err error)

RegisterRepository registers provided repository for given 'name' and with with given 'cfg' config.

Types

type Controller

type Controller struct {
	// Config is the configuration struct for the controller.
	Config *config.Controller
	// NamerFunc defines the function strategy how the model's and it's fields are being named.
	NamerFunc mapping.Namer
	// ModelMap is a mapping for the model's structures.
	ModelMap *mapping.ModelMap
	// Repositories is the mapping of the repositoryName to the repository.
	Repositories map[string]repository.Repository
}

Controller is the structure that contains, initialize and control the flow of the application. It contains repositories, model definitions.

func Default

func Default() *Controller

Default returns current default controller.

func MustNewController added in v0.15.0

func MustNewController(cfg *config.Controller) *Controller

MustNewController creates new controller for given provided 'cfg' config. Panics on error.

func NewController added in v0.15.0

func NewController(cfg *config.Controller) (*Controller, error)

NewController creates new controller for given config 'cfg'.

func NewDefault

func NewDefault() *Controller

NewDefault creates new default controller based on the default config.

func (*Controller) CloseAll added in v0.15.0

func (c *Controller) CloseAll(ctx context.Context) error

CloseAll gently closes repository connections.

func (*Controller) DialAll added in v0.15.0

func (c *Controller) DialAll(ctx context.Context) error

DialAll establish connections for all repositories.

func (*Controller) GetRepository added in v0.15.0

func (c *Controller) GetRepository(model interface{}) (repository.Repository, error)

GetRepository gets the repository for the provided model.

func (*Controller) HealthCheck added in v0.15.0

func (c *Controller) HealthCheck(ctx context.Context) (*repository.HealthResponse, error)

HealthCheck checks all repositories health.

func (*Controller) ListModels added in v0.15.0

func (c *Controller) ListModels() []*mapping.ModelStruct

ListModels returns a list of registered models for given controller.

func (*Controller) MigrateModels added in v0.15.0

func (c *Controller) MigrateModels(ctx context.Context, models ...interface{}) error

MigrateModels updates or creates provided models representation in their related repositories. A representation of model might be a database table, collection etc. Model's repository must implement repository.Migrator.

func (*Controller) ModelStruct

func (c *Controller) ModelStruct(model interface{}) (*mapping.ModelStruct, error)

ModelStruct gets the model struct on the base of the provided model

func (*Controller) MustModelStruct added in v0.15.0

func (c *Controller) MustModelStruct(model interface{}) *mapping.ModelStruct

MustModelStruct gets the model struct from the cached model Map. Panics if the model does not exists in the map.

func (*Controller) Now added in v0.15.0

func (c *Controller) Now() time.Time

Now gets and returns current timestamp. If the configs specify the function might return UTC timestamp.

func (*Controller) RegisterModels

func (c *Controller) RegisterModels(models ...interface{}) (err error)

RegisterModels registers provided models within the context of the provided Controller. All repositories must be registered up to this moment.

func (*Controller) RegisterRepository added in v0.15.0

func (c *Controller) RegisterRepository(name string, cfg *config.Repository) (err error)

RegisterRepository registers provided repository for given 'name' and with with given 'cfg' config.

Jump to

Keyboard shortcuts

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