Documentation ¶
Overview ¶
Package core 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
- Variables
- func CtxSetController(parent context.Context, c *Controller) context.Context
- type Closer
- 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) InitializeAll() (err 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) RegisterFileStore(name string, s filestore.Store) error
- func (c *Controller) RegisterModels(models ...mapping.Model) (err error)
- func (c *Controller) RegisterRepositories(repositories ...repository.Repository)
- func (c *Controller) RegisterRepositoryModels() error
- func (c *Controller) RegisterStore(name string, s store.Store) error
- func (c *Controller) SetAccountModel(account auth.Account) error
- func (c *Controller) SetDefaultFileStore(s filestore.Store) error
- func (c *Controller) SetDefaultRepository(r repository.Repository) error
- func (c *Controller) SetDefaultStore(s store.Store) error
- func (c *Controller) SetUnmappedModelRepositories() error
- type Dialer
- type Initializer
- type Options
Constants ¶
const DefaultFileStoreName = "nrn_default_file_store"
DefaultFileStoreName is the name of the default store.
const DefaultStoreName = "nrn_default_store"
DefaultStoreName is the name of the default store.
Variables ¶
var ( // ErrController defines major classification for the controller. ErrController = errors.New("controller") // ErrRepository is an error related with the repository. ErrRepository = errors.Wrap(ErrController, "repository") // ErrRepositoryNotFound is an error when repository is not found. ErrRepositoryNotFound = errors.Wrap(ErrRepository, "not found") // ErrRepositoryAlreadyRegistered class of errors when repository is already registered. ErrRepositoryAlreadyRegistered = errors.Wrap(ErrRepository, "already registered") // ErrStoreAlreadySet is an error when the store is already set at some name. ErrStoreAlreadySet = errors.Wrap(ErrController, "store already set") // ErrFileStoreAlreadySet is an error when the store is already set at some name. ErrFileStoreAlreadySet = errors.Wrap(ErrController, "file store already set") )
Functions ¶
func CtxSetController ¶ added in v0.18.0
func CtxSetController(parent context.Context, c *Controller) context.Context
CtxSetController stores the controller in the context.
Types ¶
type Closer ¶ added in v0.18.0
Closer is an interface that closes all connection for given instance.
type Controller ¶ added in v0.18.0
type Controller struct { // Options are the settings for the controller. Options *Options // Repositories are the controller registered repositories. Repositories map[string]repository.Repository // DefaultRepository is the default repository for given controller. DefaultRepository repository.Repository // ModelRepositories is the mapping between the model and related repositories. ModelRepositories map[*mapping.ModelStruct]repository.Repository // ModelMap is a mapping for the model's structures. ModelMap *mapping.ModelMap // AccountModel is the account model used by Authenticator, Tokener and Verifier. AccountModel *mapping.ModelStruct // Stores is the mapping of the stores with their names. Stores map[string]store.Store // DefaultStore is the default key-value store used by this controller. DefaultStore store.Store // Authenticator is the service authenticator. Authenticator auth.Authenticator // Tokener is the service authentication token creator. Tokener auth.Tokener // Verifier is the authorization verifier. Verifier auth.Verifier // Initializers are the components that needs to initialized, that are not repository, store or one of auth interfaces. Initializers []Initializer // NamedInitializers are the initializers with some unique name that would allow to get them back from controller. NamedInitializers map[string]Initializer // FileStores is the mapping of the stores with their names. FileStores map[string]filestore.Store // DefaultFileStore is the default file store used by this controller. DefaultFileStore filestore.Store }
Controller is the structure that contains, initialize and control the flow of the application. It contains repositories, model definitions.
func CtxGetController ¶ added in v0.18.0
func CtxGetController(ctx context.Context) (*Controller, bool)
CtxGetController gets the controller from the context.
func NewDefault ¶ added in v0.18.0
func NewDefault() *Controller
NewDefault creates new default controller based on the default config.
func (*Controller) CloseAll ¶ added in v0.18.0
func (c *Controller) CloseAll(ctx context.Context) error
CloseAll gently closes repository connections.
func (*Controller) DialAll ¶ added in v0.18.0
func (c *Controller) DialAll(ctx context.Context) error
DialAll establish connections for all repositories.
func (*Controller) GetRepository ¶ added in v0.18.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.18.0
func (c *Controller) GetRepositoryByModelStruct(mStruct *mapping.ModelStruct) (repository.Repository, error)
GetRepositoryByModelStruct gets the service by model struct.
func (*Controller) HealthCheck ¶ added in v0.18.0
func (c *Controller) HealthCheck(ctx context.Context) (*repository.HealthResponse, error)
HealthCheck checks all repositories health.
func (*Controller) InitializeAll ¶ added in v0.18.0
func (c *Controller) InitializeAll() (err error)
InitializeAll initializes all
func (*Controller) ListModels ¶ added in v0.18.0
func (c *Controller) ListModels() []*mapping.ModelStruct
ListModels returns a list of registered models for given controller.
func (*Controller) MapRepositoryModels ¶ added in v0.18.0
func (c *Controller) MapRepositoryModels(r repository.Repository, models ...mapping.Model) (err error)
MapRepositoryModels 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.18.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 ¶ added in v0.18.0
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.18.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.18.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) RegisterFileStore ¶ added in v0.18.0
func (c *Controller) RegisterFileStore(name string, s filestore.Store) error
RegisterFileStore registers file store 's' at 'name'.
func (*Controller) RegisterModels ¶ added in v0.18.0
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.18.0
func (c *Controller) RegisterRepositories(repositories ...repository.Repository)
RegisterRepositories registers provided repositories.
func (*Controller) RegisterRepositoryModels ¶ added in v0.18.0
func (c *Controller) RegisterRepositoryModels() error
RegisterRepositoryModels registers models in the repositories that implements repository.ModelRegistrar.
func (*Controller) RegisterStore ¶ added in v0.18.0
func (c *Controller) RegisterStore(name string, s store.Store) error
RegisterStore registers store 's' at 'name'.
func (*Controller) SetAccountModel ¶ added in v0.18.0
func (c *Controller) SetAccountModel(account auth.Account) error
SetAccountModel sets the account model for the controller.
func (*Controller) SetDefaultFileStore ¶ added in v0.18.0
func (c *Controller) SetDefaultFileStore(s filestore.Store) error
SetDefaultFileStore sets the default file store in the controller.
func (*Controller) SetDefaultRepository ¶ added in v0.18.0
func (c *Controller) SetDefaultRepository(r repository.Repository) error
SetDefaultRepository sets the default repository for given controller.
func (*Controller) SetDefaultStore ¶ added in v0.18.0
func (c *Controller) SetDefaultStore(s store.Store) error
SetDefaultStore sets the default store in the controller.
func (*Controller) SetUnmappedModelRepositories ¶ added in v0.18.0
func (c *Controller) SetUnmappedModelRepositories() error
SetUnmappedModelRepositories checks if all models have their repositories mapped.
type Initializer ¶
type Initializer interface {
Initialize(c *Controller) error
}
Initializer is an interface used to initialize services, repositories etc.
type Options ¶
type Options struct { AccountModel auth.Account // NamingConvention is the naming convention used while mapping the models. 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 // DefaultNotNullFields defines if the model non-pointer fields should be marked as not null by default. DefaultNotNullFields bool // ModelNotNullFields defines not null fields for specified model only. ModelNotNullFields map[mapping.Model]struct{} }
Options defines the configuration for the Options.
func DefaultOptions ¶ added in v0.19.0
func DefaultOptions() *Options
DefaultOptions are the default options for the controller.