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 CtxStore(parent context.Context, c *Controller) context.Context
- type Controller
- func (c *Controller) CloseAll(ctx context.Context) error
- func (c *Controller) DialAll(ctx context.Context) error
- func (c *Controller) GetRepository(model mapping.Model) (repository.Repository, error)
- func (c *Controller) GetRepositoryByModelStruct(mStruct *mapping.ModelStruct) (repository.Repository, error)
- func (c *Controller) HealthCheck(ctx context.Context) (*repository.HealthResponse, error)
- func (c *Controller) ListModels() []*mapping.ModelStruct
- func (c *Controller) MapRepositoryModels(r repository.Repository, models ...mapping.Model) (err error)
- func (c *Controller) MigrateModels(ctx context.Context, models ...mapping.Model) error
- func (c *Controller) ModelStruct(model mapping.Model) (*mapping.ModelStruct, error)
- func (c *Controller) MustModelStruct(model mapping.Model) *mapping.ModelStruct
- func (c *Controller) Now() time.Time
- func (c *Controller) RegisterModels(models ...mapping.Model) (err error)
- func (c *Controller) RegisterRepositories(repositories ...repository.Repository)
- func (c *Controller) SetDefaultRepository(r repository.Repository) error
- func (c *Controller) VerifyModelRepositories() error
- type Options
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 // ClassInvalidModel is the error classification for the invalid input models. ClassInvalidModel errors.Class )
Functions ¶
Types ¶
type Controller ¶
type Controller struct {
// Config is the configuration struct for the controller.
Options *Options
// ModelMap is a mapping for the model's structures.
ModelMap *mapping.ModelMap
// Repositories are the controller registered repositories.
Repositories map[string]repository.Repository
// ModelRepositories is the mapping between the model and related repositories.
ModelRepositories map[*mapping.ModelStruct]repository.Repository
// DefaultService is the default service or given controller.
DefaultRepository repository.Repository
}
Options is the structure that contains, initialize and control the flow of the application. It contains repositories, model definitions.
func CtxGet ¶ added in v0.16.0
func CtxGet(ctx context.Context) (*Controller, bool)
CtxGet gets the controller from the context.
func New ¶
func New(options *Options) *Controller
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 mapping.Model) (repository.Repository, error)
GetRepository gets the repository for the provided model.
func (*Controller) GetRepositoryByModelStruct ¶ added in v0.16.0
func (c *Controller) GetRepositoryByModelStruct(mStruct *mapping.ModelStruct) (repository.Repository, error)
GetRepositoryByModelStruct gets the service by model struct.
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) MapRepositoryModels ¶ added in v0.16.0
func (c *Controller) MapRepositoryModels(r repository.Repository, models ...mapping.Model) (err error)
MapModelsRepositories maps models to their repositories. If the model doesn't have repository name mapped then the controller would match default repository.
func (*Controller) 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 (*Controller) ModelStruct ¶
func (c *Controller) ModelStruct(model mapping.Model) (*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 mapping.Model) *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 ...mapping.Model) (err error)
RegisterModels registers provided models within the context of the provided Controller.
func (*Controller) RegisterRepositories ¶ added in v0.16.0
func (c *Controller) RegisterRepositories(repositories ...repository.Repository)
RegisterService registers provided service for given 'name' and with with given 'cfg' config.
func (*Controller) SetDefaultRepository ¶ added in v0.16.0
func (c *Controller) SetDefaultRepository(r repository.Repository) error
SetDefaultRepository sets the default repository for given controller.
func (*Controller) VerifyModelRepositories ¶ added in v0.16.0
func (c *Controller) VerifyModelRepositories() error
type Options ¶ added in v0.16.0
type Options struct {
// NamingConvention is the naming convention used while preparing the models.
// Allowed values:
// - camel
// - lower_camel
// - snake
// - kebab
NamingConvention mapping.NamingConvention
// SynchronousConnections defines if the query relation includes would be taken concurrently.
SynchronousConnections bool
// UTCTimestamps is the flag that defines the format of the timestamps.
UTCTimestamps bool
}
Options defines the configuration for the Options.