Skip to content

proposal: refactor config to allow nested items #217

@alexandrevicenzi

Description

@alexandrevicenzi

Hi,

The current configuration mechanism does not allow many useful features such as:

  • Slice types
  • Map types
  • Nested objects
  • Custom validation
  • and more

I'm trying to create a new Processor, but the configuration is extremely limited, it does not parse JSON that has types that are not hardcoded in the reflection used in ExtractConfig. The current config is a bit messy and it's hard to indetify what config belongs to which processor.

I have a proposal, refactor the config area to parse a valid JSON and allow more robust configurations. My idea of configuration would look like:

{
    "log_file" : "stderr",
    "log_level" : "info",
    "backend_config": {
        "save_process" : "HeadersParser|Header|Debugger",
        "gw_save_timeout" : "30s",
        "gw_val_rcpt_timeout" : "3s",
        "process_config": {
            // processor name as key for processor config as they shoud be unique
            "debug": {
                "log_received_mails": true
            },
            "guerrillaredisdb": {
                "sql_driver": "",
                "sql_dsn": "",
                "redis_expire_seconds": "",
                "redis_interface": ""
            },
            "mycustomprocessor": {
                "key": {
                    "subkey": {
                        "anotherkey": true
                    }
                }
            }
        }
    },
    "servers" : []
}

To acomplish this a few things must happen:

  • Use encode/json to deal with decoding, no hacks, no custom parser, no anything
  • All configs must implement an interface, that has a method IsValid, and this method validates the config for its processor
  • Backend calls IsValid for each processor that is going to be created
  • Backend only initialize the processor if IsValid succeds, if not, fail server start

This proposal has one issue:

  • It breaks compatility, v2 version would be required

I'm willing to:

  • Send the PR with all changes in this repo
  • Send a PR to processors under flashmob to upgrade to v2

Let me know what you think about, it's an interesting change I would say, and it requires code changes in many places.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions