config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2019 License: Apache-2.0 Imports: 11 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 DefaultProcessorConfig added in v0.2.1

func DefaultProcessorConfig() map[string]interface{}

DefaultProcessorConfig creates default config for the Processor.

func ViperSetDefaults

func ViperSetDefaults(v *viper.Viper)

ViperSetDefaults sets the default values for the viper config.

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
	// - lowercamel
	// - snake
	// - kebab
	NamingConvention string `mapstructure:"naming_convention" validate:"isdefault|oneof=camel lowercamel 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:"-"`

	// StrictUnmarshalMode is the flag that defines if the unmarshaling should be in a
	// strict mode that checks if incoming values are all known to the controller
	// As well as the query builder doesn't allow unknown queries
	StrictUnmarshalMode bool `mapstructure:"strict_unmarshal"`
	// EncodeLinks is the boolean used for encoding the links in the jsonapi encoder
	EncodeLinks bool `mapstructure:"encode_links"`

	// LogLevel is the current logging level
	LogLevel string `mapstructure:"log_level" validate:"isdefault|oneof=debug3 debug2 debug info warning error critical"`

	// DefaultRepositoryName defines default repositoy name
	DefaultRepositoryName string `mapstructure:"default_repository_name"`
	// DefaultRepository defines controller default repository
	DefaultRepository *Repository `mapstructure:"default_repository" validate:"-"`

	// Processor is the config used for the scope processor
	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 ReadConfig

func ReadConfig() (*Controller, error)

ReadConfig reads the config for given path.

func ReadControllerConfig

func ReadControllerConfig(name, path string) (*Controller, error)

ReadControllerConfig reads the config for the controller.

func ReadDefaultConfig

func ReadDefaultConfig() *Controller

ReadDefaultConfig reads the default configuration.

func ReadDefaultControllerConfig

func ReadDefaultControllerConfig() *Controller

ReadDefaultControllerConfig returns the default controller config.

func ReadNamedConfig

func ReadNamedConfig(name string) (*Controller, error)

ReadNamedConfig reads the config with the provided name.

func (*Controller) MapRepositories

func (c *Controller) MapRepositories() error

MapRepositories maps the repositories definitions from the controller with the model's repositories.

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
}

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 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"`
}

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