explaingit

masterminds/sprig

4,712GoAudience · developerComplexity · 2/5Setup · easy

TLDR

A Go library that adds over 100 helper functions to Go's built-in templates, covering strings, dates, math, lists, and dictionaries.

Mindmap

mindmap
  root((sprig))
    What it does
      100+ template helpers
      String manipulation
      Date formatting
      Math and conversion
    Tech stack
      Go
    Use cases
      Config generation
      Text templating
      Data formatting
    Setup
      Import library
      Pass function map
      Use in templates
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add string manipulation, date formatting, and math functions to your Go templates without writing custom helpers.

USE CASE 2

Generate config files or text output from Go templates using Sprig's utility functions.

USE CASE 3

Use Sprig's dictionary and list functions to work with complex data structures inside Go templates.

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

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.

Copy-paste prompts

Prompt 1
I'm using Go templates with Sprig. Show me how to uppercase a string, format a date, and repeat a value using Sprig functions.
Prompt 2
Write a Go template using Sprig that generates a Kubernetes ConfigMap from a map of key-value pairs.
Prompt 3
How do I add Sprig to my Go project and make all its functions available in my template engine?
Prompt 4
Show me how to use Sprig's dict and list functions to build a nested data structure inside a Go template.
Open on GitHub → Explain another repo

← masterminds on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.