config

package
v0.8.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRouterSettings added in v0.7.3

func DefaultRouterSettings() map[string]interface{}

DefaultRouterSettings gets the default router settings.

func DefaultSettings added in v0.7.1

func DefaultSettings() map[string]interface{}

DefaultSettings gets default config settings stored in a viper compatible format.

Types

type Endpoint

type Endpoint struct {
	// Forbidden defines if the endpoint should not be used
	Forbidden bool `mapstructure:"forbidden"`
	// Filters defines preset filters definitions for an endpoint
	Filters []string `mapstructure:"filters"`
	// Middlewares are the middlewares used for the provided endpoint
	Middlewares []string `mapstructure:"middlewares"`
}

Endpoint is the configuration struct for the single endpoint for model

type Gateway

type Gateway struct {
	// Router defines the router configuration
	Router *Router `mapstructure:"router"`

	// 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|isdefault"`

	// LogLevel determines log level for the gateway
	LogLevel string `mapstructure:"log_level" validate:"isdefault|oneof=debug3 debug2 debug info warning error critical"`

	// 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 defines tls certificate path
	TLSCertPath string `mapstructure:"tls_cert_path"`
	// TLSKeyPath defines tls key path
	TLSKeyPath string `mapstructure:"tls_key_path"`
}

Gateway defines the configuration for the gateway

func Default added in v0.7.1

func Default() *Gateway

Default gets default gateway configuration.

func (*Gateway) SetLogger added in v0.7.6

func (g *Gateway) SetLogger() error

SetLogger sets the logger for the gateway

type ListEndpoint

type ListEndpoint struct {
	Endpoint
	// Sorts are predefined sorting fields used by default on given endpoint.
	DefaultSorting []string `mapstructure:"sorts"`
	// Pagination are the default pagination for provided endpoint
	DefaultPagination *Pagination `mapstructure:"pagination"`
}

ListEndpoint is the endpoint config that contains default sorting and paginations.

type ModelEndpoints

type ModelEndpoints struct {
	// Create is the 'create' endpoint configuration
	Create Endpoint `mapstructure:"create"`
	// Get is the 'get single' endpoint configuration
	Get Endpoint `mapstructure:"get"`

	GetRelated      RelatedEndpoint `mapstructure:"get_related"`
	GetRelationship RelatedEndpoint `mapstructure:"get_relationship"`
	// List is the 'list' endpoint configuration.
	List ListEndpoint `mapstructure:"list"`
	// Patch is the 'patch' endpoint configuration.
	Patch             Endpoint        `mapstructure:"patch"`
	PatchRelationship RelatedEndpoint `mapstructure:"patch_relationship"`
	// Delete is the 'delete' endpoint configuration.
	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) Query

func (p *Pagination) Query() (*query.Pagination, error)

Query gets query.Pagination.

type RelatedEndpoint

type RelatedEndpoint struct {
	Endpoint
	Fields map[string]ListEndpoint `mapstructure:"fields"`
}

RelatedEndpoint is an endpoint configuration used for the get related and get relationship endpoints.

type Router

type Router struct {
	// Name gets the router by it's registered name
	Name string `mapstructure:"name"`
	// Prefix is the url prefix for the API
	Prefix string `mapstructure:"prefix"`

	// DefaultMiddlewares are the middlewares used as default for each endpoint
	// without middlewares set from the
	DefaultMiddlewares []string `mapstructure:"default_middlewares"`
	// 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"`
	// ModelEndpoins contains information about the neuron models endpoints.
	ModelsEndpoints map[string]ModelEndpoints `mapstructure:"models_endpoints"`
	// I18n support for the given gateway.
	I18n *config.I18nConfig `mapstructure:"i18n"`
	// StrictQueriesMode if true sets the strict mode for the query builder, that doesn't allow
	// unknown query keys, and unknown fields.
	StrictQueriesMode bool `mapstructure:"strict_queries"`
	// QueryErrorsLimit defines the upper limit of the error number while getting the query.
	QueryErrorsLimit 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"`
	// MarshalLinks is the default behavior for marshaling the resource links into the handler responses.
	MarshalLinks              bool `mapstructure:"marshal_links"`
	ReturnCreatedWithClientID bool `mapstructure:"return_created_with_client_id"`
}

Router contains information about the router used in the gateway

func DefaultRouter added in v0.7.1

func DefaultRouter() *Router

DefaultRouter gets default router configuration

Jump to

Keyboard shortcuts

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