-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR introduces some optimizations to router template files, which simplify the structure of the template file, improve compatibility for future HAPROXY versions, and improve maintainancibility of template-related codes. Major optimizations include: 1. Move template helper functions, as well as the mapping structure, into a new .go file named `template_helper.go` 2. Replace the non-standard form `listen stats :<port>` which is forbidden by HAPROXY 1.7.0+ with the standard form `listen stats` and `bind :<port>`. 3. Introduce two new helper functions: `firstMatch` and `isTrue`. `firstMatch` matches the regexp given in the first argument with the following string arguments and returns the first matched string, while `isTrue` is a proxy for Go's `strconv.ParseBool`. 4. Change the `env` function to take variable args: `env(name, def...)`. It accepts multiple default values, but only the first non-empty default value takes effect if the environment variable is not defined. If no default value is given, or all default values are empty, then it treats `""` as the default value. 5. Eliminate many unnecessary `{{if}}`s from the template file through the introduction of `firstMatch` function. The result is the size of the template file is significantly reduced.
- Loading branch information
Showing
6 changed files
with
532 additions
and
482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.