Template Language
SKA uses the Go Template framework for templating your upstream blueprints. Additionally, it includes all Sprig functions for extended functionality.
Go Template Basics
Go templates use double curly braces for template expressions:
Hello, {{.name}}!Variables
Access variables from your .ska-upstream.yaml inputs:
// Simple variable{{.appName}}
// With formattingApplication: {{.appName | upper}}Conditionals
{{if .enableTests}}test: enabled: true{{end}}
{{if eq .environment "production"}}replicas: 3{{else}}replicas: 1{{end}}Loops
{{range .services}}- name: {{.name}} port: {{.port}}{{end}}Pipelines
Chain functions using the pipe operator:
{{.appName | lower | replace " " "-"}}Sprig Functions
SKA includes 100+ functions from the Sprig library. Here are the most useful ones:
String Functions
| Function | Description | Example |
|---|---|---|
upper | Uppercase | {{.name | upper}} → MYAPP |
lower | Lowercase | {{.name | lower}} → myapp |
title | Title case | {{.name | title}} → Myapp |
replace | Replace string | {{.name | replace "-" "_"}} |
trim | Trim whitespace | {{.name | trim}} |
quote | Add quotes | {{.name | quote}} → "myapp" |
default | Default value | {{.port | default "8080"}} |
List Functions
// First item{{first .items}}
// Last item{{last .items}}
// Join with separator{{.tags | join ", "}}Date Functions
// Current date{{now | date "2006-01-02"}}
// Format timestamp{{.createdAt | date "Jan 2, 2006"}}Encoding Functions
// Base64 encode{{.secret | b64enc}}
// JSON encode{{.config | toJson}}
// YAML encode{{.config | toYaml}}File and Folder Names
Template syntax works in file and folder names too:
src/├── {{.appName}}/│ ├── {{.appName}}_test.go│ └── main.goWith appName: "myservice", this becomes:
src/├── myservice/│ ├── myservice_test.go│ └── main.goJinja2-like Engine
For templates that heavily use Go code (where {{ conflicts), SKA offers a Jinja2-like engine:
ska create --blueprint ./my-template --output ./project --engine jinjaThis uses {% and %} delimiters instead:
func main() { fmt.Println("Hello, {% .appName %}!")}Whitespace Control
Control whitespace around template tags:
// Trim leading whitespace{{- .appName}}
// Trim trailing whitespace{{.appName -}}
// Trim both{{- .appName -}}