package module
Version: v0.0.0-...-92e3287 Latest Latest

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

Go to latest
Published: Dec 7, 2019 License: Apache-2.0 Imports: 23 Imported by: 0


KrakenD martian

The krakend-martian package integrates the martian project into the KrakenD framework.

How to use it

Add your martian DSL definition under the "" namespace of the backend section of the config file

"extra_config": {
  "": {}

More details here:

Check the example folder for a complete demo.


  • Build and run krakend edition with martian
$ cd example
$ go install ./...
$ GOPATH/bin/example -c example/krakend.json -d -p 8000
  • Send a request to the configured endpoint
$ curl -i
  HTTP/1.1 200 OK
  Cache-Control: public, max-age=0
  Content-Type: application/json; charset=utf-8
  X-Krakend: Version undefined
  X-Krakend-Completed: true
  Date: Tue, 17 Jul 2018 11:56:33 GMT
  Content-Length: 19

  {"msg":"you rock!"}

And check the logs of the KrakenD: the request modifiers have done their job! See how {"msg":"you rock!"} was added to the payload.

[KRAKEND] ▶ DEBUG config: {[0xc4201839a0] 3s 3.6µs [] 8000 2  map[github_com/devopsfaith/krakend-gologging:map[prefix:[KRAKEND] stdout:true level:DEBUG syslog:false]] 0s 0s 0s 0s false false 0 250 0s 0s 0s 0s 0s 0s false <nil> true 1}
[KRAKEND] ▶ DEBUG Debug enabled
[KRAKEND] ▶ DEBUG URL: /__debug/supu
[KRAKEND] ▶ DEBUG Query: map[]
[KRAKEND] ▶ DEBUG Params: [{param /supu}]
[KRAKEND] ▶ DEBUG Headers: map[User-Agent:[KrakenD Version undefined] Content-Length:[19] Content-Type:[] X-Forwarded-For:[] Accept-Encoding:[gzip]]
[KRAKEND] ▶ DEBUG Body: {"msg":"you rock!"}
[GIN] | 200 |     313.798µs | | GET      /__debug/supu
[GIN] | 200 |    1.556445ms | | GET      /supu




View Source
const Namespace = ""

Namespace is the key to look for extra configuration details


View Source
var (
	// ErrEmptyValue is the error returned when there is no config under the namespace
	ErrEmptyValue = errors.New("getting the extra config for the martian module")
	// ErrBadValue is the error returned when the config is not a map
	ErrBadValue = errors.New("casting the extra config for the martian module")
	// ErrMarshallingValue is the error returned when the config map can not be marshalled again
	ErrMarshallingValue = errors.New("marshalling the extra config for the martian module")
	// ErrEmptyResponse is the error returned when the modifier receives a nil response
	ErrEmptyResponse = errors.New("getting the http response from the request executor")


func ConfigGetter

func ConfigGetter(e config.ExtraConfig) interface{}

ConfigGetter implements the config.ConfigGetter interface. It parses the extra config for the martian adapter and returns a Result wrapping the results.

func HTTPRequestExecutor

func HTTPRequestExecutor(result *parse.Result, re client.HTTPRequestExecutor) client.HTTPRequestExecutor

HTTPRequestExecutor creates a wrapper over the received request executor, so the martian modifiers can be executed before and after the execution of the request

func NewBackendFactory

func NewBackendFactory(logger logging.Logger, re client.HTTPRequestExecutor) proxy.BackendFactory

NewBackendFactory creates a proxy.BackendFactory with the martian request executor wrapping the injected one. If there is any problem parsing the extra config data, it just uses the injected request executor.

func NewConfiguredBackendFactory

func NewConfiguredBackendFactory(logger logging.Logger, ref func(*config.Backend) client.HTTPRequestExecutor) proxy.BackendFactory

NewConfiguredBackendFactory creates a proxy.BackendFactory with the martian request executor wrapping the injected one. If there is any problem parsing the extra config data, it just uses the injected request executor.

func Register

func Register()

Register gets all the modifiers from the krakend-martian register and registers them into the martian parser


type Context

type Context struct {
	// contains filtered or unexported fields

Context provides information for a single request/response pair.

func NewContext

func NewContext(parent context.Context) *Context

NewContext returns a context wrapping the received parent

func (*Context) SkipRoundTrip

func (c *Context) SkipRoundTrip()

SkipRoundTrip flags the context to skip the round trip

func (*Context) SkippingRoundTrip

func (c *Context) SkippingRoundTrip() bool

SkippingRoundTrip returns the flag for skipping the round trip

type Result

type Result struct {
	Result *parse.Result
	Err    error

Result is a simple wrapper over the parse.FromJSON response tuple

type StaticModifier

type StaticModifier struct {

StaticModifier is a martian.RequestResponseModifier that routes reqeusts to rootPath and serves the assets there, while skipping the HTTP roundtrip.

func NewStaticModifier

func NewStaticModifier(rootPath string) *StaticModifier

NewStaticModifier constructs a static.Modifier that takes a path to serve files from, as well as an optional mapping of request paths to local file paths (still rooted at rootPath).

func (*StaticModifier) ModifyRequest

func (s *StaticModifier) ModifyRequest(req *http.Request) error

ModifyRequest marks the context to skip the roundtrip and downgrades any https requests to http.


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL