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
Section titled “Go Template Basics”Go templates use double curly braces for template expressions:
Hello, {{.name}}!Variables
Section titled “Variables”Access variables from your .ska-upstream.yaml inputs:
// Simple variable{{.appName}}
// With formattingApplication: {{.appName | upper}}Conditionals
Section titled “Conditionals”{{if .enableTests}}test: enabled: true{{end}}
{{if eq .environment "production"}}replicas: 3{{else}}replicas: 1{{end}}{{range .services}}- name: {{.name}} port: {{.port}}{{end}}Pipelines
Section titled “Pipelines”Chain functions using the pipe operator:
{{.appName | lower | replace " " "-"}}Sprig Functions
Section titled “Sprig Functions”SKA includes 100+ functions from the Sprig library. Here are the most useful ones:
String Functions
Section titled “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
Section titled “List Functions”// First item{{first .items}}
// Last item{{last .items}}
// Join with separator{{.tags | join ", "}}Date Functions
Section titled “Date Functions”// Current date{{now | date "2006-01-02"}}
// Format timestamp{{.createdAt | date "Jan 2, 2006"}}Encoding Functions
Section titled “Encoding Functions”// Base64 encode{{.secret | b64enc}}
// JSON encode{{.config | toJson}}
// YAML encode{{.config | toYaml}}File and Folder Names
Section titled “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
Section titled “Jinja2-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
Section titled “Whitespace Control”Control whitespace around template tags:
// Trim leading whitespace{{- .appName}}
// Trim trailing whitespace{{.appName -}}
// Trim both{{- .appName -}}