Generate

The goht generate command is what you will be using to generate Go code from your GoHT templates.

Help

To get help with the goht generate command, you can run the following command:

$ goht help generate

You can also use the command’s help flag:

$ goht generate -h

Usage

Without any other flags, the goht generate command scans the current directory and its subdirectories for .goht files that are newer than their generated output. Those files can contain Haml, Slim, and EGO templates.

Generated files are written next to their source .goht files. Each generated file uses the same base name with a .goht.go suffix.

For example, if you have a file my_template.goht in the templates directory, the generated Go code will be in templates/my_template.goht.go.

The goht generate command also supports the --path, --force, --watch, --skip-dirs, --max-workers, and --keep flags:

  • --force - Force the generation of Go code even if the .goht.go file already exists and is newer than the .goht file.
  • --keep - Keep any orphaned .goht.go files that are not associated with a .goht file.
  • --max-workers int - The maximum number of workers to use when generating Go code. The default is the number of CPUs on the machine.
  • --path - The path to the directory containing the .goht files to generate Go code from. The default is the current directory.
  • --skip-dirs strings - A comma-separated list of directory names to skip when looking for .goht files to generate Go code from. The default is vendor,node_modules.
  • --watch - Watch the directory for changes and regenerate Go code when changes are detected.

By default, goht generate skips vendor and node_modules directories.

By default, goht generate deletes orphaned .goht.go files when their matching .goht source file is gone. Use --keep when you need to preserve generated files during a rename or migration.