config

package
v0.0.0-...-6582c30 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config defines the config structs and some config parser interfaces and implementations

Index

Constants

View Source
const (
	// BracketsRouterPatternBuilder uses brackets as route params delimiter
	BracketsRouterPatternBuilder = iota
	// ColonRouterPatternBuilder use a colon as route param delimiter
	ColonRouterPatternBuilder
)

Variables

View Source
var RoutingPattern = ColonRouterPatternBuilder

RoutingPattern to use during route conversion. By default, use the colon router pattern

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// the name of the group the response should be moved to. If empty, the response is
	// not changed
	Group string `mapstructure:"group"`
	// HTTP method of the request to send to the backend
	Method string `mapstructure:"method"`
	// Set of hosts of the API
	Host []string `mapstructure:"host"`
	// False if the hostname should be sanitized
	HostSanitizationDisabled bool `mapstructure:"disable_host_sanitize"`
	// URL pattern to use to locate the resource to be consumed
	URLPattern string `mapstructure:"url_pattern"`
	// set of response fields to remove. If empty, the filter id not used
	Blacklist []string `mapstructure:"blacklist"`
	// set of response fields to allow. If empty, the filter id not used
	Whitelist []string `mapstructure:"whitelist"`
	// map of response fields to be renamed and their new names
	Mapping map[string]string `mapstructure:"mapping"`
	// the encoding format
	Encoding string `mapstructure:"encoding"`
	// the response to process is a collection
	IsCollection bool `mapstructure:"is_collection"`
	// name of the field to extract to the root. If empty, the formater will do nothing
	Target string `mapstructure:"target"`

	// list of keys to be replaced in the URLPattern
	URLKeys []string
	// number of concurrent calls this endpoint must send to the API
	ConcurrentCalls int
	// timeout of this backend
	Timeout time.Duration
	// decoder to use in order to parse the received response from the API
	Decoder encoding.Decoder
}

Backend defines how krakend should connect to the backend service (the API resource to consume) and how it should process the received response

type EndpointConfig

type EndpointConfig struct {
	// url pattern to be registered and exposed to the world
	Endpoint string `mapstructure:"endpoint"`
	// HTTP method of the endpoint (GET, POST, PUT, etc)
	Method string `mapstructure:"method"`
	// set of definitions of the backends to be linked to this endpoint
	Backend []*Backend `mapstructure:"backend"`
	// number of concurrent calls this endpoint must send to the backends
	ConcurrentCalls int `mapstructure:"concurrent_calls"`
	// timeout of this endpoint
	Timeout time.Duration `mapstructure:"timeout"`
	// duration of the cache header
	CacheTTL time.Duration `mapstructure:"cache_ttl"`
	// list of query string params to be extracted from the URI
	QueryString []string `mapstructure:"querystring_params"`
}

EndpointConfig defines the configuration of a single endpoint to be exposed by the krakend service

type Parser

type Parser interface {
	Parse(configFile string) (ServiceConfig, error)
}

Parser reads a configuration file, parses it and returns the content as an init ServiceConfig struct

type ServiceConfig

type ServiceConfig struct {
	// set of endpoint definitions
	Endpoints []*EndpointConfig `mapstructure:"endpoints"`
	// defafult timeout
	Timeout time.Duration `mapstructure:"timeout"`
	// default TTL for GET
	CacheTTL time.Duration `mapstructure:"cache_ttl"`
	// default set of hosts
	Host []string `mapstructure:"host"`
	// port to bind the krakend service
	Port int `mapstructure:"port"`
	// version code of the configuration
	Version int `mapstructure:"version"`

	// run krakend in debug mode
	Debug bool
	// contains filtered or unexported fields
}

ServiceConfig defines the krakend service

func (*ServiceConfig) Init

func (s *ServiceConfig) Init() error

Init initializes the configuration struct and its defined endpoints and backends. Init also sanitizes the values, applies the default ones whenever necessary and normalizes all the things.

type URI

type URI int

URI implements the URIParser interface

func (URI) CleanHost

func (URI) CleanHost(host string) string

CleanHost sanitizes the received host

func (URI) CleanHosts

func (u URI) CleanHosts(hosts []string) []string

CleanHosts applies the CleanHost method to every member of the received array of hosts

func (URI) CleanPath

func (URI) CleanPath(path string) string

CleanPath trims all the extra slashes from the received URI path

func (URI) GetEndpointPath

func (u URI) GetEndpointPath(path string, params []string) string

GetEndpointPath applies the proper replacement in the received path to generate valid route patterns

type URIParser

type URIParser interface {
	CleanHosts([]string) []string
	CleanHost(string) string
	CleanPath(string) string
	GetEndpointPath(string, []string) string
}

URIParser defines the interface for all the URI manipulation required by KrakenD

func NewURIParser

func NewURIParser() URIParser

NewURIParser creates a new URIParser using the package variable RoutingPattern

Source Files

  • config.go
  • parser.go
  • uri.go

Directories

Path Synopsis
Package viper defines a config parser implementation based on the viper pkg
Package viper defines a config parser implementation based on the viper pkg

Jump to

Keyboard shortcuts

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