krakend

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: Apache-2.0 Imports: 57 Imported by: 1

README

Krakend logo

KrakenD API Gateway

Ultra-High performance API Gateway with middlewares

KrakenD Community Edition (or KrakenD-CE) is the binary distribution of KrakenD.

In this repository, you'll find the utils to build the KrakenD binary yourself. If you want to use KrakenD download the binary

KrakenD Site | Documentation | Blog | Twitter

Features

Some of the features you get with KrakenD are:

  • Ultra-High performance API Gateway
  • Backend for Frontend
  • Efficient: Super low memory consumption with high traffic (usually under 50MB w/ +1000 concurrent) and even lower with low traffic (under 5MB)
  • Easy to use: Declaration of endpoints by just writing the /url/patterns/and/{variables}
  • Unlimited number of backends and endpoints associated with each endpoint. The limit is your kernel.
  • Aggregation of all the data in the backends for a single endpoint
  • Response composition and data manipulation (capture, groups, renames...)
  • Response filtering (whitelist and blacklist)
  • Concurrent API calls to the backend for the same request
  • Simple configuration: All application configuration and behavior declared in a krakend.json.
  • Friendly: No development needed to build your gateway. Use the Visual API Designer (UI to generate the krakend.json)
  • SSL
  • HTTP2 ready
  • Circuit breaker (fail fast and avoid smashing stressed backends)
  • Bursting on High-load
  • Logging and statistics of usage
  • API with statistics
  • Service Discovery: DNS SRV, ETCD or add your own
  • Multiple encodings supported (json, XML, RSS or response as single string)
  • Injections via DSL in the configuration (Martian)
  • Throttling: Limits of usage in the router and proxy layers.
  • User quota: Restrict usage of users by IP or custom headers
  • Basic Firewalling: Restrict connections by host, drop connections on certain limits
  • Automatic load balancing
  • HTTP Cache headers
  • In-memory backend response cache
  • Multiple installation options (bin, docker, rpm, deb, brew)
  • Cloud native
  • Loved by orchestrators (Kubernetes, Mesos + Marathon, Nomad, Docker Swarm, and others)
  • Secure:
    • Support for SSL
    • OAuth client grant
    • JSON Web Tokens (JWT) and JSON Object Signing and Encryption (JOSE)
    • HTTP Strict Transport Security (HSTS)
    • Clickjacking protection
    • HTTP Public Key Pinning (HPKP)
    • MIME-Sniffing prevention
    • Cross-site scripting (XSS) protection
    • Cross-origin resource sharing (CORS)

For a more nice description of the features have a look in the website.

Gateway documentation

Full, comprehensive documentation is viewable on the KrakenD website:

http://www.krakend.io/docs/overview/introduction/

Build Requirements

  • golang 1.11

Build

    make build

Building with docker

If you don't have or don't want to install go you can build it using the golang docker container.

make docker_build

FPM

You can set up your fpm docker image to run setting DOCKER_FPM on the Makefile.

Using the generated packages

The package creates a krakend user to run the service and configures the service to run under systemd.

Linux Distributions

  • just any Linux (using the tar.gz)
  • Ubuntu
  • Debian
  • CentOS/RedHat

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadPlugins

func LoadPlugins(folder, pattern string, logger logging.Logger)

LoadPlugins loads and registers the plugins so they can be used if enabled at the configuration

func NewBackendFactory

func NewBackendFactory(logger logging.Logger, metricCollector *metrics.Metrics) proxy.BackendFactory

NewBackendFactory creates a BackendFactory by stacking all the available middlewares: - oauth2 client credentials - http cache - martian - pubsub - amqp - cel - lua - rate-limit - circuit breaker - metrics collector - opencensus collector

func NewBackendFactoryWithContext

func NewBackendFactoryWithContext(ctx context.Context, logger logging.Logger, metricCollector *metrics.Metrics) proxy.BackendFactory

NewBackendFactory creates a BackendFactory by stacking all the available middlewares and injecting the received context

func NewEngine

func NewEngine(cfg config.ServiceConfig, logger logging.Logger, w io.Writer) *gin.Engine

NewEngine creates a new gin engine with some default values and a secure middleware

func NewExecutor

func NewExecutor(ctx context.Context) cmd.Executor

NewExecutor returns an executor for the cmd package. The executor initalizes the entire gateway by registering the components and composing a RouterFactory wrapping all the middlewares.

func NewHandlerFactory

func NewHandlerFactory(logger logging.Logger, metricCollector *metrics.Metrics, rejecter jose.RejecterFactory) router.HandlerFactory

NewHandlerFactory returns a HandlerFactory with a rate-limit and a metrics collector middleware injected

func NewProxyFactory

func NewProxyFactory(logger logging.Logger, backendFactory proxy.BackendFactory, metricCollector *metrics.Metrics) proxy.Factory

NewProxyFactory returns a new ProxyFactory wrapping the injected BackendFactory with the default proxy stack and a metrics collector

func RegisterEncoders

func RegisterEncoders()

RegisterEncoders registers all the available encoders

func RegisterSubscriberFactories

func RegisterSubscriberFactories(ctx context.Context, cfg config.ServiceConfig, logger logging.Logger) func(n string, p int)

RegisterSubscriberFactories registers all the available sd adaptors

Types

type BackendFactory

type BackendFactory interface {
	NewBackendFactory(context.Context, logging.Logger, *metrics.Metrics) proxy.BackendFactory
}

BackendFactory returns a KrakenD backend factory, ready to be passed to the KrakenD proxy factory

type BloomFilterJWT

type BloomFilterJWT struct{}

BloomFilterJWT is the default TokenRejecterFactory implementation.

func (BloomFilterJWT) NewTokenRejecter

func (t BloomFilterJWT) NewTokenRejecter(ctx context.Context, cfg config.ServiceConfig, l logging.Logger, reg func(n string, p int)) (jose.ChainedRejecterFactory, error)

NewTokenRejecter registers the bloomfilter component and links it to a token rejecter. Then it returns a chained rejecter factory with the created token rejecter and other based on the CEL component.

type DefaultRunServerFactory added in v1.2.0

type DefaultRunServerFactory struct{}

DefaultRunServerFactory creates the default RunServer by wrapping the injected RunServer with the plugin loader and the CORS module

func (*DefaultRunServerFactory) NewRunServer added in v1.2.0

type EngineFactory

type EngineFactory interface {
	NewEngine(config.ServiceConfig, logging.Logger, io.Writer) *gin.Engine
}

EngineFactory returns a gin engine, ready to be passed to the KrakenD RouterFactory

type ExecutorBuilder

type ExecutorBuilder struct {
	LoggerFactory               LoggerFactory
	PluginLoader                PluginLoader
	SubscriberFactoriesRegister SubscriberFactoriesRegister
	TokenRejecterFactory        TokenRejecterFactory
	MetricsAndTracesRegister    MetricsAndTracesRegister
	EngineFactory               EngineFactory
	ProxyFactory                ProxyFactory
	BackendFactory              BackendFactory
	HandlerFactory              HandlerFactory
	RunServerFactory            RunServerFactory

	Middlewares []gin.HandlerFunc
}

ExecutorBuilder is a composable builder. Every injected property is used by the NewCmdExecutor method.

func (*ExecutorBuilder) NewCmdExecutor

func (e *ExecutorBuilder) NewCmdExecutor(ctx context.Context) cmd.Executor

NewCmdExecutor returns an executor for the cmd package. The executor initalizes the entire gateway by delegating most of the tasks to the injected collaborators. They register the components and compose a RouterFactory wrapping all the middlewares. Every nil collaborator is replaced by the default one offered by this package.

type HandlerFactory

type HandlerFactory interface {
	NewHandlerFactory(logging.Logger, *metrics.Metrics, jose.RejecterFactory) router.HandlerFactory
}

HandlerFactory returns a KrakenD router handler factory, ready to be passed to the KrakenD RouterFactory

type LoggerBuilder

type LoggerBuilder struct{}

LoggerBuilder is the default BuilderFactory implementation.

func (LoggerBuilder) NewLogger

NewLogger sets up the logging components as defined at the configuration.

type LoggerFactory

type LoggerFactory interface {
	NewLogger(config.ServiceConfig) (logging.Logger, io.Writer, error)
}

LoggerFactory returns a KrakenD Logger factory, ready to be passed to the KrakenD RouterFactory

type MetricsAndTraces

type MetricsAndTraces struct{}

MetricsAndTraces is the default implementation of the MetricsAndTracesRegister interface.

func (MetricsAndTraces) Register

Register registers the metrcis, influx and opencensus packages as required by the given configuration.

type MetricsAndTracesRegister

type MetricsAndTracesRegister interface {
	Register(context.Context, config.ServiceConfig, logging.Logger) *metrics.Metrics
}

MetricsAndTracesRegister registers the defined observability components and returns a metrics collector, if required.

type PluginLoader

type PluginLoader interface {
	Load(folder, pattern string, logger logging.Logger)
}

PluginLoader defines the interface for the collaborator responsible of starting the plugin loaders

type ProxyFactory

type ProxyFactory interface {
	NewProxyFactory(logging.Logger, proxy.BackendFactory, *metrics.Metrics) proxy.Factory
}

ProxyFactory returns a KrakenD proxy factory, ready to be passed to the KrakenD RouterFactory

type RunServer added in v1.2.0

RunServer defines the interface of a function used by the KrakenD router to start the service

type RunServerFactory added in v1.2.0

type RunServerFactory interface {
	NewRunServer(logging.Logger, router.RunServerFunc) RunServer
}

RunServerFactory returns a RunServer with several wraps around the injected one

type SubscriberFactoriesRegister

type SubscriberFactoriesRegister interface {
	Register(context.Context, config.ServiceConfig, logging.Logger) func(string, int)
}

SubscriberFactoriesRegister registers all the required subscriber factories from the available service discover components and adapters and returns a service register function. The service register function will register the service by the given name and port to all the available service discover clients

type TokenRejecterFactory

type TokenRejecterFactory interface {
	NewTokenRejecter(context.Context, config.ServiceConfig, logging.Logger, func(string, int)) (jose.ChainedRejecterFactory, error)
}

TokenRejecterFactory returns a jose.ChainedRejecterFactory containing all the required jose.RejecterFactory. It also should setup and manage any service related to the management of the revocation process, if required.

Directories

Path Synopsis
cmd
Package tests implements utility functions to help with API Gateway testing.
Package tests implements utility functions to help with API Gateway testing.

Jump to

Keyboard shortcuts

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