# Template project
Template project contains all the directories and files that you think you must have in every project. Files inside a
template can have actions (opens new window) which will
be templated (opens new window) with the values. For example, if you have an action
like {{ .Port }}
and Port
key in your values, it will be replaced with the
corresponding value.
Template project address will be used in properties YAML. Template project can be in a git repository and the URL
of .git
repository can be used in a properties YAML. Template can also be compressed as .tar.gz
file
with package command. Compressed .tar.gz
file can be hosted in HTTP server or in a git
repository and the URL to .tar.gz
can be used in a properties YAML.
TIP
The suggested way to store template projects is to host all template projects in one git repository. For every template
project, you can create orphan branches with git checkout --orphan orphan_name
command and set branch
in the project
structure to orphan_name
. Common files can be stored in the main
branch. See example projects:
Empty go project (opens new window)
Standard go project (opens new window)
Common files (opens new window)
To address files in the properties yaml, you can use raw URL (opens new window) of the files.
# Default values in template project
You can use default values in your templates. Let's assume that user entered module name
github.com/denigursoy/foo
and you create new packages in your template project. In order to import from other package,
you need to know module name user entered. You can access it with .ModuleName
value. See the following example:
# Templating directory and file names
You can use values in directory or file names in your template project. For example, you can use ProjectName
default
value in your files/directories of template project. If user enters module name as github.com/denigursoy/foo
and
then ProjectName
default value will be foo
. During the templating file with the name {{ .ProjectName
}}.txt
will be foo.txt
.
# Using sprig functions
During templating, you can use sprig functions (opens new window). For example, You can use uuidv4
function of spring to generate unique IDs.
# Templating with go template library
You can also use other go template library's capabilities such as conditions, iterating array values, etc. For more information see go template library (opens new window).
See simple examples to learn templating.