dag: Support Go template syntax
- Dominant language
- Go
- Stars
- 4k
- Forks
- 332
- Avg merge
- 19h 9m
- Merged PRs (30d)
- 137
Description
**Overview**
Enhance Dagu's configuration files with Go template support, enabling dynamic content generation and variable substitution using Go's `template/text` package. Additionally, incorporate the rich set of utility functions from [`sprig`](https://masterminds.github.io/sprig/) to provide powerful template operations.
**Features**
- Full Go template syntax support in most configuration fields
- Access to all sprig template functions (string operations, math, lists, etc.)
- Variable substitution across configuration
- Environment variable support
- Built-in helper functions
**Example Usage**
Basic variable substitution:
```yaml
name: example
params:
NAME: "World"
GREETING: "Hello"
steps:
- name: simple-greeting
command: "{{.GREETING}}, {{.NAME}}!"
```
Using sprig functions:
```yaml
name: templating-example
params:
USER: "alice"
ENV: "production"
steps:
- name: conditional-step
command: |
{{- if eq .ENV "production" -}}
deploy --production --user {{.USER | upper}}
{{- else -}}
deploy --staging --user {{.USER | lower}}
{{- end -}}
- name: date-based-task
command: "backup-{{now | date \"2006-01-02\"}}.tar.gz"
```
Environment variables can be accessed using the `env` function:
```yaml
steps:
- name: env-aware
command: "deploy --token {{env "API_TOKEN"}}"
```
This enhancement would make Dagu configurations more flexible and powerful, allowing for dynamic content generation based on variables, environment, and runtime conditions.
Contributor guide
Assessment
This issue has not been assessed yet.