Add Configuration Settings
Occasionally we need a new setting to be created so that users have a bit more control over the inner workings of NCA. This details the process of adding settings:
- Open up
src/config/config.goand add a value to the Config struct. - Choose the data type. In most cases a primitive is fine: string, int, float64, etc.
- Decide if the value should be pulled directly from the
settingsfile or if you need to massage data manually. The former is usually the best option, but not always possible. - If the value is pulled directly from
settings, set up the struct tags:- At a minimum you must define which
settingsvalue will populate the Go config structure; e.g., theconfig.Ghostscriptvalue specifiessetting:"GHOSTSCRIPT"in the struct tag, telling us thesettingsfile’s “GHOSTSCRIPT” value is to be used. - If you want validation, use a “type” struct tag, e.g., the “Webroot”
setting uses
type:"url"to specify that the value must be a valid URL.
- At a minimum you must define which
- If the value is not directly pulled from
settings, modifyParse()to read the raw setting and set the config field accordingly. - Open
settings-exampleand add the setting with some documentation (bash-style comments) explaning what it does and how it should be used. When you can, make sure the default “just works” with a standard docker setup.
Notes:
- If you need more validation than what is provided, you can add that to the
Parse()function.MinimumIssuePages, for instance, ensures it’s always at least 1. - If you add a workflow path, you may need to alter
test/copy-sources.goin order to automatically create that path for testing.