config

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config contains configuration structures used by all neuron packages.

Index

Constants

This section is empty.

Variables

View Source
var (
	// MjrConfig is the major config error classification.
	MjrConfig errors.Major
	// ClassConfigInvalidValue is the errors classification for invalid config values.
	ClassConfigInvalidValue errors.Class
)

Functions

func DefaultValues added in v0.15.0

func DefaultValues() map[string]interface{}

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

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"`
	// 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"`
	// DefaultRepositoryName defines default repository name
	DefaultRepositoryName string `mapstructure:"default_repository_name"`
	// DefaultRepository defines controller default repository
	DefaultRepository *Repository `mapstructure:"default_repository"`
	// DisallowDefaultRepository determines if the default repository are allowed.
	DisallowDefaultRepository bool `mapstructure:"disallow_default_repository"`
	// AsynchronousIncludes defines if the query relation includes would be taken concurrently.
	AsynchronousIncludes bool `mapstructure:"asynchronous_includes"`
	// UTCTimestamps is the flag that defines the format of the timestamps.
	UTCTimestamps bool `mapstructure:"utc_timestamps"`
}

Controller defines the configuration for the Controller.

func DefaultController added in v0.15.0

func DefaultController() *Controller

DefaultController returns default controller configuration.

func (*Controller) MapModelsRepositories added in v0.15.0

func (c *Controller) MapModelsRepositories() error

MapModelsRepositories maps the repositories configurations for all model's.

func (*Controller) SetDefaultRepository

func (c *Controller) SetDefaultRepository() error

SetDefaultRepository sets the default repository for given controller.

func (*Controller) Validate added in v0.15.0

func (c *Controller) Validate() error

Validate checks the validity of the config.

type Field added in v0.15.0

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 Many2Many added in v0.15.0

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 {
	// NeuronCollectionName 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"`
	// Select 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.15.0

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 RelationStrategy added in v0.15.0

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"`
	// 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"`
	// TLS defines the tls configuration for given repository.
	TLS *tls.Config
}

Repository defines the repository configuration variables.

func (*Repository) Parse added in v0.15.0

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=postgres'

func (*Repository) Validate added in v0.15.0

func (r *Repository) Validate() error

Validate validates the repository config.

type Strategy added in v0.15.0

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