kragin

module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: GPL-3.0

README ยถ

โš ๏ธ This project isn't stable at the moment. Use in production at your own risk!

kragin ๐Ÿš€

Version: v0.3.1
Description: The package provides a set of tools for developing KrakenD plugins.
Compatibility: package dependency compatibility version and KrackenD (v0.3.1 <-> v2.6.1)

Welcome to kragin! This repository contains various helper packages that simplify plugin creation for the KrakenD API Gateway.

Features โœจ

  • Log: Minimalistic logging interface + a no-op implementation.
  • Populator: Struct field populator with tag-based configuration loading.
  • Plugin: Easy-to-use โ€œmodifierโ€ helpers for requests/responses.
  • Registerer: Tools to register custom logic or transformations in Krakend.
  • Wrapper: Utilities for request manipulation (body reading, form parsing, headers, etc.).

Installation ๐Ÿ”ง

To use kragin in your own Go module, run:

go get github.com/dumb-tech/kragin@v0.3.1

Then import the packages you need:

package yourplugin

import (
    "github.com/dumb-tech/kragin/log"
    "github.com/dumb-tech/kragin/populator"
    "github.com/dumb-tech/kragin/plugin"
    "github.com/dumb-tech/kragin/registerer"
    "github.com/dumb-tech/kragin/wrapper"
)

Packages Overview ๐Ÿ“‘

1. log

Defines a Logger interface with typical logging methods:

type Logger interface {
    Debug(v ...any)
    Info(v ...any)
    Warning(v ...any)
    Error(v ...any)
    Critical(v ...any)
    Fatal(v ...any)
}

Includes a NoopLogger that does nothing (useful for testing or quiet modes). If you'll implement RegisterLoggermethod then no-op logger is useful for wait before this method will be called by KrakenD.

2. populator

Allows you to populate struct fields from a map[string]any using struct tags:

// Example struct
type Config struct {
    Host string `krakend:"host,required=true"`
    Port int    `krakend:"port,default=8080"`
}

// Usage
cfg := &Config{}
err := populator.PopulatePluginConfig(myConfigStore, "myconfig", cfg)
// Now cfg.Host, cfg.Port, etc. are populated!
  • Supports default values (default=...)
  • Supports required fields (required=true)
  • Supports nested structs

3. plugin

Helps create plugin modifiers for request/response transformations:

p := plugin.NewModifier("my-awesome-plugin", "v1.0.0")

func (app *Application) requestHandlerFunc(config configuration.Configuration, deps *dependencies) func(any) (any, error) {
    return func(request any) (any, error) {
        r, ok := request.(wrapper.Request)
        if !ok {
            return request, wrapper.ErrUnknownRequestDataType(request)
        }
        req := wrapper.Modifier(r)
        
        req.SetHeader("X-Custom-Secret-Key", "my-secret-key")
        
        return req, nil
    }
}

RequestHandler and ResponseHandler let you add request/response modifiers. Under the hood, uses registerer.ModifierRegisterer.

4. registerer

Core interfaces and helper types for plugin registration in Krakend:

  • Registerer interface for modifiers, handlers, clients.
  • ModifierRegisterer for adding request/response modifiers or custom ones.

5. wrapper

Utilities for working with incoming requests:

  • Request interface to get context, headers, params, body, etc.
  • RequestWrapper for reading/changing the body, manipulating query params, and more.

Contributing ๐Ÿค

We โค contributions! Feel free to open issues or submit pull requests.

License ๐Ÿ“„

This project is licensed under the GNU General Public License v3.0 (GPLv3).

This Markdown made with ChatGPT o1

Directories ยถ

Path Synopsis

Jump to

Keyboard shortcuts

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