config

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: 9 Imported by: 0

Documentation

Overview

Package config contains configuration structures used by all neuron-core packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConcurrentProcessorConfig added in v0.2.1

func DefaultConcurrentProcessorConfig() map[string]interface{}

DefaultConcurrentProcessorConfig creates default concurrent config for the Processor.

func DefaultThreadsafeProcessorConfig added in v0.8.2

func DefaultThreadsafeProcessorConfig() map[string]interface{}

DefaultThreadsafeProcessorConfig creates default config for the Processor.

func DefaultValues added in v0.11.0

func DefaultValues() map[string]interface{}

DefaultValues returns default config values in a spf13/viper compatible way.

func RegisterProcessor added in v0.11.0

func RegisterProcessor(name string, p *Processor) error

RegisterProcessor registers processor 'p' under provided 'name'

Types

type Connection

type Connection struct {
	// Host defines the access hostname or the ip address
	Host string `mapstructure:"host" validate:"hostname|ip"`

	// Path is the connection path, just after the protocol and
	Path string `mapstructure:"path" validate:"isdefault|uri"`

	// Port is the connection port
	Port interface{} `mapstructure:"port"`

	// Protocol is the protocol used in the connection
	Protocol string `mapstructure:"protocol"`

	// RawURL is the raw connection url. If set it must define the protocol ('http://',
	// 'rpc://'...)
	RawURL string `mapstructure:"raw_url" validate:"isdefault|url"`

	// Username is the username used to get connection credential
	Username string `mapstructure:"username"`

	// Password is the password used to get connection credentials
	Password string `mapstructure:"password"`

	// Options contains connection dependent specific options
	Options map[string]interface{} `mapstructure:"options"`

	// MaxTimeout defines the maximum timeout for the given repository connection
	MaxTimeout *time.Duration `mapstructure:"max_timeout"`
}

Connection is the configuration for non local schemas credentials. The connection config can be set by providing raw_url or with host,path,protocol.

type Controller

type Controller struct {
	// NamingConvention is the naming convention used while preparing the models.
	// Allowed values:
	// - camel
	// - lower_camel
	// - snake
	// - kebab
	NamingConvention string `mapstructure:"naming_convention" validate:"isdefault|oneof=camel lower_camel snake kebab"`
	// Models defines the model's configurations.
	Models map[string]*ModelConfig `mapstructure:"models"`
	// Repositories contains the connection configs for the given repository instance name
	Repositories map[string]*Repository `mapstructure:"repositories" validate:"-"`
	// DefaultRepositoryName defines default repository name
	DefaultRepositoryName string `mapstructure:"default_repository_name"`
	// DefaultRepository defines controller default repository
	DefaultRepository *Repository `mapstructure:"default_repository" validate:"-"`
	// DisallowDefaultRepository determines if the default repository are allowed.
	DisallowDefaultRepository bool `mapstructure:"disallow_default_repository"`

	// Processor is the config used for the scope processor
	ProcessorName string     `mapstructure:"processor_name"`
	Processor     *Processor `mapstructure:"processor" validate:"required"`

	// CreateValidatorAlias is the alias for the create validators
	CreateValidatorAlias string `mapstructure:"create_validator_alias"`
	// PatchValidatorAlias is the alis used for the Patch validator
	PatchValidatorAlias string `mapstructure:"patch_validator_alias"`
	// DefaultValidatorAlias is the alias used as a default validator alias
	DefaultValidatorAlias string `mapstructure:"default_validator_alias"`

	// IncludedDepthLimit is the default limit for the nested included query paremeter.
	// Each model can specify its custom limit in the model's config.
	IncludedDepthLimit int `mapstructure:"included_depth_limit"`
}

Controller defines the configuration for the Controller.

func Default added in v0.11.0

func Default() *Controller

Default returns default controller configuration.

func (*Controller) MapModelsRepositories added in v0.11.0

func (c *Controller) MapModelsRepositories() error

MapModelsRepositories maps the repositories configurations for all model's.

func (*Controller) MapProcessor added in v0.11.0

func (c *Controller) MapProcessor() error

MapProcessor if the processor name is provided maps it to registered processors. Returns error if the processor is not defined.

func (*Controller) SetDefaultRepository

func (c *Controller) SetDefaultRepository() error

SetDefaultRepository sets the default repository for given controller.

type Field added in v0.2.2

type Field struct {
	// Flags stores the field flags.
	Flags     []string          `mapstructure:"flags" validate:"isdefault|oneof=client-id nofilter hidden nosort iso8601 i18n omitempty langtag many2many"`
	Strategy  *RelationStrategy `mapstructure:"strategy"`
	Many2Many *Many2Many        `mapstructure:"many2many"`
}

Field is the model's field configuration.

type I18nConfig

type I18nConfig struct {
	// SupportedLanguages represent supported languages tags
	SupportedLanguages []string `mapstructure:"supported_languages"`
}

I18nConfig defines i18n configuration support.

type Many2Many added in v0.2.3

type Many2Many struct {
	JoinTableModel    string `mapstructure:"join_table_model"`
	ForeignKey        string `mapstructure:"foreign_key"`
	RelatedForeignKey string `mapstructure:"related_foreign_key"`
}

Many2Many is the many2many relation configuration.

type ModelConfig

type ModelConfig struct {
	// Collection is the model's collection name
	Collection string `mapstructure:"collection"`
	// RepositoryName is the model's repository name, with the name provided in the initialization
	// process...
	RepositoryName string `mapstructure:"repository_name"`
	// Store sets the model's Store values
	Store map[string]interface{} `mapstructure:"map"`
	// Repository defines the model's repository connection config
	Repository *Repository `mapstructure:"repository"`
	// AutoMigrate automatically migrates the model into the given repository structuring
	// I.e. sql creates or updates the table
	AutoMigrate bool `mapstructure:"automigrate"`
	// Fields contains the model fields configuration.
	Fields map[string]*Field `mapstructure:"fields"`
	// IncludedDepthLimit is the per model nested include depth limit.
	IncludedDepthLimit *int `mapstructure:"included_depth_limit"`
}

ModelConfig defines single model configurations.

type OnDeleteStrategy added in v0.2.3

type OnDeleteStrategy struct {
	QueryOrder     uint   `mapstructure:"query_order"`
	OnError        string `mapstructure:"on_error" validate:"isdefault|oneof=fail continue"`
	RelationChange string `mapstructure:"relation_change" validate:"isdefault|oneof=restrict cascade noaction setnull"`
}

OnDeleteStrategy is the configuration for the 'on delete' option, relation strategy. It is a strategy that defines modification query order, reaction 'on error' and the reaction on root deletion 'relation_change' - when the root model is being deleted, how should the related model change. Possible options are: - set null - (default) - sets the related model foreign key to 'null' or 'empty'. - restrict - doesn't allow to delete the root model if it contains any relation value. - no action - does nothing with the related foreign key. - cascade - related data is being deleted when the parent data is being deleted.

type ProcessList

type ProcessList []string

ProcessList is a list of the processes.

type Processor

type Processor struct {
	// DefaultTimeout is the default timeout used for given processor.
	DefaultTimeout time.Duration `mapstructure:"default_timeout"`
	// CreateProcesses are the default processes used in the create method.
	CreateProcesses ProcessList `mapstructure:"create_processes"`
	// DeleteProcesses are the default processes used in the delete method.
	DeleteProcesses ProcessList `mapstructure:"delete_processes"`
	// GetProcesses are the default processes used in the get method.
	GetProcesses ProcessList `mapstructure:"get_processes"`
	// ListProcesses are the default processes used in the list method.
	ListProcesses ProcessList `mapstructure:"list_processes"`
	// PatchProcesses are the default processes used in the patch method.
	PatchProcesses ProcessList `mapstructure:"patch_processes"`
	// CountProcesses are the processes used for count method.=
	CountProcesses ProcessList `mapstructure:"count_processes"`
}

Processor is the config used for the scope processor.

func ConcurrentProcessor added in v0.3.0

func ConcurrentProcessor() *Processor

ConcurrentProcessor creates the concurrent processor confuration.

func GetProcessor added in v0.11.0

func GetProcessor(name string) (*Processor, bool)

GetProcessor gets the processor with the 'name'.

func ThreadSafeProcessor added in v0.3.0

func ThreadSafeProcessor() *Processor

ThreadSafeProcessor creates the goroutine safe query processor configuration.

func (*Processor) Validate

func (p *Processor) Validate() error

Validate validates the processor values.

type RelationStrategy added in v0.2.3

type RelationStrategy struct {
	OnCreate Strategy         `mapstructure:"on_create"`
	OnDelete OnDeleteStrategy `mapstructure:"on_delete"`
	OnPatch  Strategy         `mapstructure:"on_patch"`
}

RelationStrategy is the configuration of the relation modification strategy.

type Repository

type Repository struct {
	// DriverName defines the name for the repository driver
	DriverName string `mapstructure:"driver_name" validate:"required"`
	// Host defines the access hostname or the ip address
	Host string `mapstructure:"host" validate:"isdefault|hostname|ip"`
	// Path is the connection path, just after the protocol and
	Path string `mapstructure:"path" validate:"isdefault|uri"`
	// Port is the connection port
	Port int `mapstructure:"port"`
	// Protocol is the protocol used in the connection
	Protocol string `mapstructure:"protocol"`
	// RawURL is the raw connection url. If set it must define the protocol ('http://',
	// 'rpc://'...)
	RawURL string `mapstructure:"raw_url" validate:"isdefault|url"`
	// Username is the username used to get connection credential
	Username string `mapstructure:"username"`
	// Password is the password used to get connection credentials
	Password string `mapstructure:"password"`
	// Options contains connection dependent specific options
	Options map[string]interface{} `mapstructure:"options"`
	// MaxTimeout defines the maximum timeout for the given repository connection
	MaxTimeout *time.Duration `mapstructure:"max_timeout"`
	// DBName gets the database name
	DBName string `mapstructure:"dbname"`
	// SSLMode defines if the ssl is enabled
	SSLMode string `mapstructure:"sslmode"`
}

Repository defines the repository configuration variables.

func (*Repository) Parse added in v0.2.1

func (r *Repository) Parse(s string) error

Parse parses the repository configuration from the whitespace separated key value string. I.e. 'host=172.16.1.1 port=5432 username=some password=pass drivername=pq'

func (*Repository) Validate added in v0.2.1

func (r *Repository) Validate() error

Validate validates the repository config.

type Strategy added in v0.2.3

type Strategy struct {
	QueryOrder uint   `mapstructure:"query_order"`
	OnError    string `mapstructure:"on_error" validate:"isdefault|oneof=fail continue"`
}

Strategy is the configuration strategy for the relations.

Jump to

Keyboard shortcuts

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