Skip to content

Questions about setting the path to the config file path on the command line in Kong  #351

@pauluzee

Description

@pauluzee

I am using Kong for the first time after having used other Go CLI toolkits (so far: Cobra and Go-flags).

Our team has an idiom for optionally specifying a config file path on the command line (always with --configFile or -c ). The expectation is that if the user sets the config file path on the command line, the app will use that value to locate the file and not check all of the other "standard" locations (e.g., the home dir, in the same directory as the executable, etc.). Also, if the user sets configFile with an invalid path, the app will exit with an error message.

If the user doesn't set configFile on the command line, however, then the app checks all of the standard locations and loads the first file it finds. Most of the time, it is not considered an error if the app doesn't find a config file, but I can see times when we would want the app to exit immediately with an error message when it can't find a config file.

In all cases we want to know exactly which file was loaded; to avoid confusion, most of our apps log the full, absolute path of the file that initialized the application.

I would like to use the configuration loading mechanism built into Kong, but I'm having a hard time figuring out how to pass a user-supplied path to it. I've written and tested a method that returns the "first valid" path to a config file, but it expects the user-supplied path as a parameter. If that's empty, then it iterates over the list of standard locations and returns the first one it finds. While I see how to use a "BeforeApply" method to run this sort of init stuff, it's not clear to me where inside of Kong I can get the optional value from the command line. Is there a method inside of the Kong instance that I can get the value of a specific flag (such as *configFile). In other words, how do I read the value of configFile from the command line before Kong locates and loads the config file? Also, how do I get the Kong configuration file built-in to exit the app if it can't find a file?

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