KrakenD config example

What is KrakenD?

KrakenD is your self-designed REST API Gateway that feeds from your existing data services (Your APIs, legacy, cloud, IoT…) Just define visually or in a configuration file the endpoints your applications will use and the KrakenD will fetch and transform the content at your will for you.

https://www.krakend.io

Configuration example(proxy for POST, GET requests):

{
  "version": 2,
  "extra_config": {
    "github_com/devopsfaith/krakend-gologging": {
      "level": "WARNING",
      "prefix": "[KRAKEND]",
      "syslog": false,
      "stdout": true
    },
    "github_com/devopsfaith/krakend-metrics": {
      "collection_time": "60s",
      "proxy_disabled": false,
      "router_disabled": false,
      "backend_disabled": false,
      "endpoint_disabled": false,
      "listen_address": ":8090"
    },
    "github_com/devopsfaith/krakend-cors": {
      "allow_origins": [ "*" ],
      "allow_methods": [ "POST", "GET", "PUT", "DELETE" ],
      "allow_headers": [
        "Origin",
        "Authorization",
        "Content-Type",
        "Accept",
        "X-Auth-Token"
      ],
      "expose_headers": [ "Content-Length" ],
      "max_age": "12h"
    }
  },
  "timeout": "3000ms",
  "cache_ttl": "300s",
  "output_encoding": "no-op",
  "name": "api-proxy",
  "port": 80,
  "endpoints": [
    {
      "endpoint": "/",
      "extra_config": {},
      "output_encoding": "no-op",
      "concurrent_calls": 1,
      "backend": [
        {
          "url_pattern": "/",
          "encoding": "no-op",
          "extra_config": {},
          "sd": "static",
          "host": [
            "http://some-landing"
          ],
          "disable_host_sanitize": false
        }
      ]
    },
    {
      "method": "GET",
      "endpoint": "/api/v1/endpoint}",
      "extra_config": {},
      "output_encoding": "no-op",
      "concurrent_calls": 1,
      "backend": [
        {
          "method": "POST",
          "url_pattern": "/api/v1/{endpoint}",
          "encoding": "no-op",
          "extra_config": {},
          "sd": "static",
          "host": [
            "http://backend-service-getter"
          ],
          "disable_host_sanitize": false
        }
      ]
    },
    {
      "method": "POST",
      "endpoint": "/api/v1/endpoint}",
      "extra_config": {},
      "output_encoding": "no-op",
      "concurrent_calls": 1,
      "backend": [
        {
          "method": "POST",
          "url_pattern": "/api/v1/{endpoint}",
          "encoding": "no-op",
          "extra_config": {},
          "sd": "static",
          "host": [
            "http://backend-service-poster"
          ],
          "disable_host_sanitize": false
        }
      ]
    },
}

go build failed with “errors.go:121:2: undefined: stack”

Problem that I have met today:

$ go build
# github.com/pkg/errors
../../../../pkg/mod/github.com/pkg/errors@v0.8.0/errors.go:121:2: undefined: stack

#How to solve

I don't know the source of the problem, but I have fixed it with upgrading errors package version in my go.mod file:

module github.com/project_package
require (
// ...
github.com/pkg/errors v0.8.1 // indirect
// ...
)

[Щепотка мудрости] Качество решений не определяет результат

«Качество решений не определяет результат, — отметил Канеман в выступлении. — Можно принять очень хорошее решение и получить плохой результат, потому что не повезло. А можно принять плохое решение и получить хороший результат, если повезет».

Источник: vc.ru

Golang 1.11.2: dep ensure failed

Problem:


$ dep ensure
panic: version queue is empty, should not happen
goroutine 1 [running]:
github.com/golang/dep/gps.(*solver).findValidVersion(0xc00021e000, 0xc00026ac80, 0xc0001e6440, 0x1, 0x1, 0x0, 0xc0001e6440)
/home/travis/gopath/src/github.com/golang/dep/gps/solver.go:915 +0x4ec
github.com/golang/dep/gps.(*solver).createVersionQueue(0xc00021e000, 0xc0003ab0c1, 0x14, 0x0, 0x0, 0xc0001e6440, 0x1, 0x1, 0x0, 0x0, ...)
/home/travis/gopath/src/github.com/golang/dep/gps/solver.go:902 +0x46e
github.com/golang/dep/gps.(*solver).solve(0xc00021e000, 0xa64e60, 0xc0000a8188, 0x7c72ab, 0x936c80, 0xc00003c060)
/home/travis/gopath/src/github.com/golang/dep/gps/solver.go:505 +0x611
github.com/golang/dep/gps.(*solver).Solve(0xc00021e000, 0xa64e60, 0xc0000a8188, 0xdfa9c8, 0xc00002c0dc, 0x1f, 0xc00019b5c0)
/home/travis/gopath/src/github.com/golang/dep/gps/solver.go:440 +0xc0
main.(*ensureCommand).runUpdate(0xc000185960, 0xc0000c6980, 0xc00019a860, 0x0, 0x0, 0xc0000f6090, 0xa68f00, 0xc0000afc80, 0xc00002c0c4, 0x37, ...)
/home/travis/gopath/src/github.com/golang/dep/cmd/dep/ensure.go:356 +0x1c0
main.(*ensureCommand).Run(0xc000185960, 0xc0000c6980, 0xc00019a860, 0x0, 0x0, 0x0, 0x0)
/home/travis/gopath/src/github.com/golang/dep/cmd/dep/ensure.go:216 +0x7d4
main.(*Config).Run(0xc0000af0e0, 0x0)
/home/travis/gopath/src/github.com/golang/dep/cmd/dep/main.go:212 +0x1070
main.main()
/home/travis/gopath/src/github.com/golang/dep/cmd/dep/main.go:84 +0x53d
The command "dep ensure -update" failed and exited with 2 during .

Solution:

Add to your Gopkg.toml this lines:


[[override]]
name = "gopkg.in/fsnotify.v1"
source = "gopkg.in/fsnotify/fsnotify.v1"

And try to start dep ensure again.

Рабочий пример Kafka в docker / docker-compose

version: '3.4'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
kafka:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper
ports:
- 9092:9092
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

docker-compose bind volume

Необходимо было разобраться с тем как сделать bind volume в 3+ синтаксисе docker-compose, решение ниже:

При поднятии приложения нужно устанавливать переменную окружения APPROOT, которая указывает на корневую директорию приложения:

APPROOT=[local source path] docker-compose up -d