Skip to content

SpaceCafe/miniplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

miniplate

miniplate is a lightweight, size-optimized drop-in replacement for gomplate, designed for use in minimal Docker images where binary size matters. It implements the most commonly used template functions while deliberately omitting cloud provider integrations, remote datasource fetching, and other heavy dependencies that inflate the compiled binary.

YAML and TOML support are opt-in via build tags, keeping the default binary as small as possible. Templates written for gomplate are compatible with miniplate as long as they only use supported functions.

Requirements

  • Go: Version 1.25 or higher.
  • UPX (optional): Used by the default make target to further compress the binary.

Installation

go install -trimpath -ldflags="-s -w" github.com/spacecafe/miniplate/cmd/miniplate@latest

To include TOML and/or YAML support (adds to binary size):

go install -tags=toml,yaml -trimpath -ldflags="-s -w" github.com/spacecafe/miniplate/cmd/miniplate@latest

Or build from source with maximum compression via UPX:

make

Usage

miniplate accepts the same flags as gomplate:

Flag Aliases Description
--in <file> -i, --file, -f Input template file (- for stdin, default)
--out <file> -o Output file (- for stdout, default)
--input-dir <dir> Process all files in a directory recursively
--output-dir <dir> Write output to this directory (requires --input-dir)
--exclude <pattern> Exclude files matching a glob pattern (repeatable)
--context <name=URL> Add a data source as .<name> in templates (repeatable)

Examples:

# Render a template from stdin
echo '{{ env.Getenv "HOME" }}' | miniplate

# Render a file with a JSON context
miniplate --in config.tmpl --out config.yaml --context cfg=data.json

# Process a directory of templates
miniplate --input-dir templates/ --output-dir output/ --exclude '*.skip'

# Read a secret from a file via _FILE suffix
SECRET_FILE=/run/secrets/token miniplate --in app.tmpl

Compatibility

The table below compares miniplate against gomplate v4. Function name links point to the gomplate documentation. ⚠️ indicates opt-in support via build tags.

Group Function (aliases) gomplate miniplate Notes
base64 base64.Decode
base64.DecodeBytes
base64.Encode
coll coll.Dict (dict)
coll.Keys
coll.Slice
coll coll.Append
coll.Flatten
coll.GoSlice
coll.Has
coll.Index
coll.JQ
coll.JSONPath
coll.Merge
coll.Omit
coll.Pick
coll.Prepend
coll.Reverse
coll.Set
coll.Sort
coll.Uniq
coll.Unset
coll.Values
conv conv.Atoi
conv.Bool (bool)
conv.Default (default)
conv.Join (join)
conv.ParseInt
conv.ParseFloat
conv.ToBool
conv.ToBools
conv.ToInt
conv.ToInt64
conv.ToInt64s
conv.ToInts
conv.ToFloat64
conv.ToFloat64s
conv.ToString
conv.ToStrings
conv.URL (urlParse)
conv conv.ParseUint
conv conv.Float (float)
conv.Int (int)
conv.String (string)
Convenience aliases for ToFloat64, ToInt, ToString
crypto crypto.AESEncrypt
crypto.AESDecrypt
crypto.ECDSAGenerateKey
crypto.Ed25519GenerateKey
crypto.RSAGenerateKey
crypto.RSAEncrypt
crypto.RSADecrypt
crypto.RSADerivePublicKey
crypto.PBKDF2
crypto.WPAPSK
crypto crypto.Bcrypt
crypto.SHA224
crypto.SHA256
crypto.SHA384
crypto.SHA512
crypto.SHA224Bytes
crypto.SHA256Bytes
crypto.SHA384Bytes
crypto.SHA512Bytes
crypto crypto.MD5
crypto.MD5Bytes
data data.JSON (json)
data.JSONArray (jsonArray)
data.ToJSON (toJSON)
data.ToJSONPretty (toJSONPretty)
data data.YAML (yaml)
data.YAMLArray (yamlArray)
data.ToYAML (toYAML)
⚠️ Requires -tags=yaml
data data.TOML (toml)
data.ToTOML (toTOML)
⚠️ Requires -tags=toml
data data.XML (xml)
data.ToXML (toXML)
data.ToXMLPretty (toXMLPretty)
data data.CSV
data.CSVByRow
data.CSVByColumn
datasource (ds)
datasourceExists
datasourceReachable
defineDatasource
listDatasources
include
Remote datasources not supported
env env.Getenv (getenv) Also supports VAR_FILE suffix: if SECRET_FILE is set, reads the value from the file at that path
env env.MustGetenv Like env.Getenv but fails if the variable is unset or empty
env env.Env
env.ExpandEnv
env.HasEnv
file file.Exists
file.IsDir
file.Read
file.ReadDir
file.Stat
file.Write
file file.IsFile
file file.Walk
human human.Bytes
human.ParseBytes
human.ToBytes
Human-readable byte sizes via go-humanize
math math.Abs
math.Add (add)
math.Ceil
math.Div (div)
math.Floor
math.IsFloat
math.IsInt
math.IsNum
math.Max
math.Min
math.Mul (mul)
math.Pow (pow)
math.Rem (rem)
math.Round
math.Seq (seq)
math.Sub (sub)
strings strings.Contains
strings.HasPrefix
strings.HasSuffix
strings.Quote (quote)
strings.Repeat
strings.ReplaceAll (replaceAll)
strings.ShellQuote (shellQuote)
strings.Slug
strings.Split
strings.SplitN
strings.Squote (squote)
strings.Title (title)
strings.ToLower (toLower)
strings.ToUpper (toUpper)
strings.Trim
strings.TrimLeft
strings.TrimRight
strings.TrimPrefix
strings.TrimSuffix
strings.TrimSpace (trimSpace)
strings.Trunc
strings strings.Abbrev
strings.CamelCase
strings.Indent (indent)
strings.KebabCase
strings.RuneCount
strings.SkipLines
strings.SnakeCase
strings.WordWrap
tmpl tmpl.Exec
tmpl.Inline (tpl)
tmpl.Path
tmpl.PathDir
uuid uuid.IsValid
uuid.Nil
uuid.V1
uuid.V4
uuid uuid.Parse
uuid uuid.V6
uuid.V7
RFC 9562 UUID versions
aws aws.* Cloud integrations not included
gcp gcp.* Cloud integrations not included
filepath filepath.*
net net.* DNS lookups, CIDR helpers
path path.*
random random.*
regexp regexp.*
semver semver.*
sockaddr sockaddr.*
test test.*
time time.*

About

Reduced version of [gomplate](/hairyhenderson/gomplate.git) as a drop-in replacement

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors