dnscontrol/docs/_functions/global/require_glob.md
Patrik Kernstock 576c2bd582
New feature: require_glob() (similar to require() but supports globs) (#804)
* Initial implementation of findFiles/globe/glob

* Fixed path, some small improvements

* filepath.Dir() calls Clean() automatically anyway

* Relative path support (like require()), renamed func

* Check file ext prefix, further comments, var renaming

* Updated static.go after merge

* Added doc for glob()

* Tiny adjustment of description of glob()

* Updated docs for possible pattern

* Reworked glob, added public-facing require_glob()

* Updated docs with examples

* Updated static.go

* go generate
2020-08-19 14:00:40 -04:00

1.1 KiB

name parameters
require_glob
path
recursive

require_glob() can recursively load .js files, optionally non-recursive as well.

Possible parameters are:

  • Path as string, where you would like to start including files. Mandatory. Pattern matching possible, see GoLand path/filepath/#Match docs.
  • If being recursive. This is a boolean if the search should be recursive or not. Define either true or false. Default is true.

Example to load .js files recursively:

require_glob("./domains/");

Example to load .js files only in domains/:

require_glob("./domains/", false);

One more important thing to note: require_glob() is as smart as require() is. It loads files always relative to the JavaScript file where it's being executed in. Let's go with an example, as it describes it better:

dnscontrol.js:

require("domains/index.js");

domains/index.js:

require_glob("./user1/");

This will now load files being present underneath ./domains/user1/ and NOT at below ./domains/, as require_glob() is called in the subfolder domains/.