Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: refactor config to allow nested items #217

Open
alexandrevicenzi opened this issue Oct 15, 2020 · 1 comment
Open

proposal: refactor config to allow nested items #217

alexandrevicenzi opened this issue Oct 15, 2020 · 1 comment

Comments

@alexandrevicenzi
Copy link

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.

@flashmob
Copy link
Owner

flashmob commented Oct 15, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants