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

Support for centralized configuration and shared variables in separate Tengo scripts #428

Open
pokeyaro opened this issue Aug 13, 2023 · 1 comment

Comments

@pokeyaro
Copy link

Description:
I'm currently using Tengo scripts for configuration management in my application. I have a central configuration script (base.tengo) that defines global settings like whether certain features (e.g., MySQL, Redis) should be enabled or not. I then have separate environment-specific scripts (dev.tengo and prod.tengo) that use these global settings to set up connection parameters for different environments.

Here's the structure:

config/base.tengo (Defines global settings)
config/dev.tengo (Specific settings for the development environment)
config/prod.tengo (Specific settings for the production environment)
main.go (Runs the configuration updater)
However, I'm facing an issue where I want to control these global settings in the base.tengo script and share them with the environment-specific scripts (dev.tengo, prod.tengo) without having to modify main.go. In other words, I want to achieve centralized configuration management and share these settings among the different Tengo scripts.

Currently, I'm facing difficulties in importing the global settings from base.tengo into dev.tengo and prod.tengo. The import paths seem to be causing issues, and I'm looking for a way to share these settings across different scripts seamlessly.

MyCode:

config/base.tengo

export func() {
    return {
        mysqlEnabled: true
    }
}()

config/dev.tengo

ctl := import("./config/base")

mysql := func() {
    if ctl.mysqlEnabled {
        return {
            host: "dev.mysql.com",
            port: 3306,
            username: "dev_user",
            password: "dev_pass",
            dbname: "dev_db"
        }
    }
    return {}
}()

Is there a recommended approach or any updates planned that would enable centralized configuration management and sharing of variables among separate Tengo scripts? This would greatly improve the maintainability and flexibility of the configuration setup.

Thank you for your time and consideration!

@geseq
Copy link
Collaborator

geseq commented Aug 22, 2023

Can you explain what difficulties you're actually facing?

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