โ ๏ธ 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