Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
github.com/Masterminds/sprig/v3
The Go language comes with a built-in template language, but not very many template functions. Sprig is a library that provides more than 100 commonly used template functions.
It is inspired by the template functions found in Twig and in various JavaScript libraries, such as underscore.js.
Sprig leverages mergo to handle merges. In its v0.3.9 release, there was a behavior change that impacts merging template functions in sprig. It is currently recommended to use v0.3.10 or later of that package. Using v0.3.9 will cause sprig tests to fail.
There are two active major versions of the sprig
package.
master
branch. The Go API should
remain compatible with v2, the current stable version. Behavior change behind
some functions is the reason for the new major version.Template developers: Please use Sprig's function documentation for detailed instructions and code snippets for the >100 template functions available.
Go developers: If you'd like to include Sprig as a library in your program, our API documentation is available at GoDoc.org.
For standard usage, read on.
To load the Sprig FuncMap
:
import (
"github.com/Masterminds/sprig/v3"
"html/template"
)
// This example illustrates that the FuncMap *must* be set before the
// templates themselves are loaded.
tpl := template.Must(
template.New("base").Funcs(sprig.FuncMap()).ParseGlob("*.html")
)
By convention, all functions are lowercase. This seems to follow the Go idiom for template functions (as opposed to template methods, which are TitleCase). For example, this:
{{ "hello!" | upper | repeat 5 }}
produces this:
HELLO!HELLO!HELLO!HELLO!HELLO!
We followed these principles to decide which functions to add and how to implement them:
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.