controller

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: Apache-2.0 Imports: 12 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

This section is empty.

Functions

This section is empty.

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 namer.Namer
	// CreateValidator is used as a validator for the Create processes.
	CreateValidator *validator.Validate
	// PatchValidator is used as a validator for the Patch processes.
	PatchValidator *validator.Validate

	// 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, validators.

var DefaultController *Controller

DefaultController is the Default controller used if no 'controller' is provided for operations

func Default

func Default() *Controller

Default returns current default controller.

func MustGetNew

func MustGetNew(cfg *config.Controller) *Controller

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

func New

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

New 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.12.0

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

CloseAll gently closes repository connections.

func (*Controller) DialAll added in v0.12.0

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

DialAll establish connections for all repositories.

func (*Controller) GetRepository added in v0.2.1

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

GetRepository gets the repository for the provided model.

func (*Controller) HealthCheck added in v0.14.1

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

HealthCheck checks all repositories health.

func (*Controller) ListModels added in v0.5.1

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

ListModels returns a list of registered models for given controller.

func (*Controller) MigrateModels added in v0.14.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) MustGetModelStruct added in v0.6.0

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

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

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.2.1

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