Add string manipulation, date formatting, and math functions to your Go templates without writing custom helpers.
Generate config files or text output from Go templates using Sprig's utility functions.
Use Sprig's dictionary and list functions to work with complex data structures inside Go templates.
Sprig is a Go library that adds over 100 helper functions to Go's built-in templating system. Go ships with a templating language that lets you generate text output from data, but the set of functions available inside those templates is quite limited by default. Sprig fills that gap by providing a large collection of commonly needed functions for things like string manipulation, math, date formatting, type conversion, and working with lists and dictionaries. The library draws inspiration from the Twig templating language (used in PHP) and from JavaScript utility libraries like underscore.js. All the functions follow a lowercase naming convention, matching Go's own template style. You use them by piping values through function calls inside your templates, for example turning a string to uppercase or repeating it a set number of times. For Go developers, using Sprig means importing it and passing its function map to the template engine before loading any templates. Once that is done, all of Sprig's functions become available inside every template the engine processes. The README includes a short code example showing exactly how to set this up. The project has two major versions in active use. Version 3 is the current stable release and lives on the main branch. Version 2 is the previous stable release, still receiving bug fixes, and is documented on a separate branch. The two versions are mostly API-compatible, with some behavior differences in a few functions being the reason for the version bump. The README also outlines the principles behind which functions were included: they handle formatting, layout, and simple conversions, they do not fetch data from outside sources, and they do not override any of Go's built-in template functions.
← masterminds on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.