Documentation ¶
Index ¶
- Constants
- func ViperSetDefaults(v *viper.Viper)
- type Builder
- type Config
- type Connection
- type Controller
- type Endpoint
- type EndpointConstraints
- type Flags
- type Gateway
- type I18nConfig
- type ModelConfig
- type ModelEndpoints
- type Pagination
- type PresetQuery
- type PresetScope
- type ProcessList
- type Processor
- type Repository
- type Router
- type Schema
Constants ¶
const ( // FlUseLinks is the Flag that allows to return query links FlUseLinks uint = iota // FlReturnPatchContent is a flag that sets the behaviour of returning the patch content for the request FlReturnPatchContent // FlAddMetaCountList is a flag that adds the count list to the meta as a default behavior FlAddMetaCountList // FlAllowClientID is a flag that allows to use the Client defined ID FlAllowClientID // FlAllowForeignKeyFilter is the flag that allows filtering over foreign keys FlAllowForeignKeyFilter // FlUseFilterValueLimit is the flag that checks if there is any limit for the filter values FlUseFilterValueLimit // FlAllowStringSearch is a flag that defines if the string field may be filtered using // operators like: '$contains', '$startswith', '$endswith' FlAllowStringSearch )
Variables ¶
This section is empty.
Functions ¶
func ViperSetDefaults ¶
ViperSetDefaults sets the default values for the viper config
Types ¶
type Builder ¶
type Builder struct { // StrictQueriesMode if true sets the strict mode for the query builder, that doesn't allow // unknown query keys StrictQueriesMode bool `mapstructure:"strict_queries"` // ErrorLimits defines the upper limit of the error number while getting the query ErrorLimits int `validate:"min=1,max=20" mapstructure:"error_limit"` // IncludeNestedLimit is a maximum value for nested includes (i.e. IncludeNestedLimit = 1 // allows ?include=posts.comments but does not allow ?include=posts.comments.author) IncludeNestedLimit int `validate:"min=1,max=20" mapstructure:"include_nested_limit"` // FilterValueLimit is a maximum length of the filter values FilterValueLimit int `validate:"min=1,max=50" mapstructure:"filter_value_limit"` // Processor is the query processor for the query builder Processor *Processor `validate:"required" mapstructure:"processor"` }
Builder is the config used for building the queries on incoming requests
type Config ¶
type Config struct { // Controller defines the configuration for the Controllers Controller *Controller `mapstructure:"controller"` // Gateway is the configuration for the gateway Gateway *Gateway `mapstructure:"gateway"` }
Config contains general configurations for the Neuron service
func ReadDefaultConfig ¶
func ReadDefaultConfig() *Config
ReadDefaultConfig reads the default configuration
func ReadNamedConfig ¶
ReadNamedConfig reads the config with the provided name
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"` // DefaultSchema is the default schema name for the models within given controller DefaultSchema string `validate:"alphanum" mapstructure:"default_schema"` // ModelSchemas defines the model schemas used by api ModelSchemas map[string]*Schema `mapstructure:"schemas"` // 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"` // Debug sets the debug mode for the controller. Debug bool `mapstructure:"debug"` // Flags defines the controller default flags Flags *Flags `mapstructure:"flags"` // Repositories contains the connection configs for the given repository instance name Repositories map[string]*Repository `mapstructure:"repositories" validate:"-"` // 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"` }
Controller defines the configuration for the Controller
func ReadControllerConfig ¶
func ReadControllerConfig(name, path string) (*Controller, error)
ReadControllerConfig reads the config for the controller
func ReadDefaultControllerConfig ¶
func ReadDefaultControllerConfig() *Controller
ReadDefaultControllerConfig returns the default controller config
func (*Controller) MapRepositories ¶
func (c *Controller) MapRepositories(s *Schema) error
MapRepositories maps the repositories definitions from the controller with the model's repositories
func (*Controller) SetDefaultRepository ¶
func (c *Controller) SetDefaultRepository() error
SetDefaultRepository sets the default repository if defined
type Endpoint ¶
type Endpoint struct { // Forbidden defines if the endpoint should not be used Forbidden bool `mapstructure:"forbidden"` // PresetFilters defines preset filters definitions for an endpoint PresetFilters []string `mapstructure:"preset_filters"` // PresetScope defines preset scopes for an endpoint PresetScope []string `mapstructure:"preset_scope"` // PrecheckFilters are the endpoints filters used to check the consistency of the query PrecheckFilters []string `mapstructure:"precheck_filters"` // PrecheckScope are the endpoint scopes used to check the consistency of the query PrecheckScope []string `mapstructure:"precheck_scope"` // PresetSorts are the sort fields used by default on given endpoint PresetSorts []string `mapstructure:"preset_sorts"` // PresetPagination are the default pagination for provided endpoint PresetPagination *Pagination `mapstructure:"preset_pagination"` // Flags contains boolean flags used by default on given endpoint Flags Flags `mapstructure:"flags"` // RelatedField contains constraints for the relationship or related (endpoint) field RelatedField EndpointConstraints `mapstructure:"related"` // CustomMiddlewares are the middlewares used for the provided endpoint CustomMiddlewares []string `mapstructure:"custom_middlewares"` }
Endpoint is the configuration struct for the single endpoint for model
type EndpointConstraints ¶
type EndpointConstraints struct { // PrecheckFilters are the endpoints filters used to check the consistency of the query PresetFilters []string `mapstructure:"preset_filters"` // PresetScope defines preset scopes for an endpoint PresetScope []string `mapstructure:"preset_scope"` // PrecheckFilters are the endpoints filters used to check the consistency of the query PrecheckFilters []string `mapstructure:"precheck_filters"` // PrecheckScope are the endpoint scopes used to check the consistency of the query PrecheckScope []string `mapstructure:"precheck_scope"` // PresetSorts are the sort fields used by default on given endpoint PresetSorts []string `mapstructure:"preset_sorts"` // PresetPagination are the default pagination for provided endpoint PresetPagination *Pagination `mapstructure:"preset_pagination"` }
EndpointConstraints contains constraints for provided endpoints
type Gateway ¶
type Gateway struct { // Port is the port used by the gateway service Port int `mapstructure:"port" validate:"required"` // Hostname is the hostname used by the gateway service Hostname string `mapstructure:"hostname" validate:"hostname"` // ReadTimeout is the maximum duration for reading the entire // request, including the body. // // Because ReadTimeout does not let Handlers make per-request // decisions on each request body's acceptable deadline or // upload rate, most users will prefer to use // ReadHeaderTimeout. It is valid to use them both. ReadTimeout time.Duration `mapstructure:"read_timeout"` // ReadHeaderTimeout is the amount of time allowed to read // request headers. The connection's read deadline is reset // after reading the headers and the Handler can decide what // is considered too slow for the body. ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout"` // WriteTimeout is the maximum duration before timing out // writes of the response. It is reset whenever a new // request's header is read. Like ReadTimeout, it does not // let Handlers make decisions on a per-request basis. WriteTimeout time.Duration `mapstructure:"write_timeout"` // IdleTimeout is the maximum amount of time to wait for the // next request when keep-alives are enabled. If IdleTimeout // is zero, the value of ReadTimeout is used. If both are // zero, ReadHeaderTimeout is used. IdleTimeout time.Duration `mapstructure:"idle_timeout"` // ShutdownTimeout defines the time (in seconds) in which the server would shutdown // On the os.Interrupt event ShutdownTimeout time.Duration `mapstructure:"shutdown_timeout"` TLSCertPath string `mapstructure:"tls_cert_path"` // Router defines the router configuration Router *Router `mapstructure:"router"` // QueryBuilder contains the query builder config QueryBuilder *Builder `mapstructure:"query_builder"` I18n *I18nConfig `mapstructure:"i18n"` }
Gateway defines the configuration for the gateway
func ReadDefaultGatewayConfig ¶
func ReadDefaultGatewayConfig() *Gateway
ReadDefaultGatewayConfig returns the default gateway configuration
func ReadGatewayConfig ¶
ReadGatewayConfig reads the gateway config from the provided path and for given config name
type I18nConfig ¶
type I18nConfig struct { // SupportedLanguages represent supported languages tags SupportedLanguages []string }
I18nConfig defines i18n configuration support
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"` // Endpoints defines model's api endpoints configuration Endpoints ModelEndpoints `mapstructure:"endpoints"` // Map sets the model's Store values Map 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"` }
ModelConfig defines single model configurations
type ModelEndpoints ¶
type ModelEndpoints struct { Create Endpoint `mapstructure:"create"` Get Endpoint `mapstructure:"get"` GetRelated Endpoint `mapstructure:"get_related"` GetRelationship Endpoint `mapstructure:"get_relationship"` List Endpoint `mapstructure:"list"` Patch Endpoint `mapstructure:"patch"` Delete Endpoint `mapstructure:"delete"` }
ModelEndpoints is the api endpoint's configuration for the given model
type Pagination ¶
type Pagination struct { Limit int `mapstructure:"limit"` Offset int `mapstructure:"offset"` PageSize int `mapstructure:"page_size"` PageNumber int `mapstructure:"page_number"` }
Pagination defines the pagination configuration
func (Pagination) IsZero ¶
func (p Pagination) IsZero() bool
IsZero defines if the pagination configis not set
type PresetQuery ¶
type PresetQuery struct { // Field defines the field to that the values should be set with Field string // ScopeRelations gets the values by the collection relations // i.e. if the collection 'blog' has a relationship of kind to many 'posts' // // Trying to filter the 'posts' by the specific blogs values can be made by providing // the ScopeRelations value i.e.: 'blogs.posts' with the Filter: '[blogs][id][$eq]=1' // This result with the possible ScopeRelations string Filters []string }
PresetQuery is the query that is used to set up some values initialy from the other collections or by applying the filters
type PresetScope ¶
PresetScope is the preset scope values
type Processor ¶
type Processor struct { DefaultTimeout time.Duration `mapstructure:"default_timeout"` // CreateProcesses are the default processes used inthe create method CreateProcesses ProcessList `mapstructure:"create_processes"` // DeleteProcesses are the default processes used inthe delete method DeleteProcesses ProcessList `mapstructure:"delete_processes"` // GetProcesses are the default processes used inthe get method GetProcesses ProcessList `mapstructure:"get_processes"` // ListProcesses are the default processes used inthe list method ListProcesses ProcessList `mapstructure:"list_processes"` // PatchProcesses are the default processes used inthe patch method PatchProcesses ProcessList `mapstructure:"patch_processes"` }
Processor is the config used for the scope processor
type Repository ¶
type Repository struct { // DriverName defines the name for the repository driver DriverName string `mapstructure:"driver_name"` // 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"` // 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
type Router ¶
type Router struct { // Name gets the router by it's registered name Name string `mapstructure:"name"` // DefaultMiddlewares are the middlewares used as default for each endpoint // without middlewares set from the DefaultMiddlewares []string `mapstructure:"default_middlewares"` // Prefix is the url prefix for the API Prefix string `mapstructure:"prefix"` // DefaultPagination defines default ListPagination for the gateway DefaultPagination *Pagination `mapstructure:"default_pagination"` // CompressionLevel defines the compression level for the handler function writers CompressionLevel int `mapstructure:"compression_level" validate:"max=9,min=-2"` }
Router contains information about the router used in the gateway
type Schema ¶
type Schema struct { Name string `mapstructure:"name"` Models map[string]*ModelConfig `mapstructure:"models"` Local bool `mapstructure:"local"` Connection *Connection `mapstructure:"connection"` }
Schema defines configuration for the single model schema. If the schema is not local the