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 ¶
- Variables
- func CloseAll(ctx context.Context) error
- func DialAll(ctx context.Context) error
- func GetRepository(model interface{}) (repository.Repository, error)
- func HealthCheck(ctx context.Context) (*repository.HealthResponse, error)
- func MigrateModels(ctx context.Context, models ...interface{}) error
- func ModelStruct(model interface{}) (*mapping.ModelStruct, error)
- func MustModelStruct(model interface{}) *mapping.ModelStruct
- func MustNew(cfg *config.Controller)
- func New(cfg *config.Controller) (err error)
- func Now() time.Time
- func RegisterModels(models ...interface{}) (err error)
- func RegisterRepository(name string, cfg *config.Repository) (err error)
- type Controller
- func (c *Controller) CloseAll(ctx context.Context) error
- func (c *Controller) DialAll(ctx context.Context) error
- func (c *Controller) GetRepository(model interface{}) (repository.Repository, error)
- func (c *Controller) HealthCheck(ctx context.Context) (*repository.HealthResponse, error)
- func (c *Controller) ListModels() []*mapping.ModelStruct
- func (c *Controller) MigrateModels(ctx context.Context, models ...interface{}) error
- func (c *Controller) ModelStruct(model interface{}) (*mapping.ModelStruct, error)
- func (c *Controller) MustModelStruct(model interface{}) *mapping.ModelStruct
- func (c *Controller) Now() time.Time
- func (c *Controller) RegisterModels(models ...interface{}) (err error)
- func (c *Controller) RegisterRepository(name string, cfg *config.Repository) (err error)
Constants ¶
This section is empty.
Variables ¶
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 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
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
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 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.