Files
go_goutils/tplx/sprigx/README.adoc
brent saner 1bd6e1256c v1.16.3
ADDED:
* Much more functions to tplx/sprigx
2026-01-29 19:02:21 -05:00

37 KiB
Raw Blame History

SprigX

Table of Contents

1. What is SprigX?

SprigX are extensions to the sprig library (Go docs).

They provide functions that offer more enriched use cases and domain-specific data.

Tip

If you are reading this README on the Go Module Directory documentation (https://pkg.go.dev/r00t2.io/goutils/tplx/sprigx) or the directory landing page (https://git.r00t2.io/r00t2/go_goutils/src/branch/master/tplx/sprigx), it may not render correctly.

Be sure to view it at properly via the AsciiDoc rendering or by downloading and viewing the HTML version.

2. How do I Use SprigX?

The same way you would sprig!

Like this.
package main

import (
	htmlTplLib "html/template"
	txtTplLib "text/template"

	"r00t2.io/goutils/tplx/sprigx"
)

var (
	txtTpl *txtTplLib.Template = txtTplLib.
		New("").
		Funcs(
			sprigx.TxtFuncMap(),
		)
	htmlTpl *htmlTplLib.Template = htmlTplLib.
		New("").
		Funcs(
			sprigx.HtmlFuncMap(),
		)
)

They can even be combined/used together.

Like this.
package main

import (
	"text/template"

	"github.com/Masterminds/sprig/v3"
	"r00t2.io/goutils/tplx/sprigx"
)

var txtTpl *template.Template = template.
		New("").
		Funcs(
			sprigx.TxtFuncMap(),
		).
		Funcs(
			sprig.TxtFuncMap(),
		)
// Or:
/*
var txtTpl *template.Template = template.
		New("").
		Funcs(
			sprig.TxtFuncMap(),
		).
		Funcs(
			sprigx.TxtFuncMap(),
		)
 */

If a <template>.FuncMap is added via .Funcs() after template parsing, it will override any functions of the same name of a <template>.FuncMap before parsing.

For example, if both sprig and sprigx provide a function foo:

this will use foo from sprigx

(show)
package main

import (
	"text/template"

	"github.com/Masterminds/sprig/v3"
	"r00t2.io/goutils/tplx/sprigx"
)

const (
	myTpl string = `{{ "This is an example template string." | foo }}`
)

var (
	tpl *template.Template = template.Must(
					template.
						New("").
						Funcs(sprig.TxtFuncMap()).
						Parse(myTpl),
				).
				Funcs(sprigx.TxtFuncMap())
)

whereas this will use foo from sprig

(show)
package main

import (
	"text/template"

	"github.com/Masterminds/sprig/v3"
	"r00t2.io/goutils/tplx/sprigx"
)

const (
	myTpl string = `{{ "This is an example template string." | foo }}`
)

var (
	tpl *template.Template = template.Must(
					template.
						New("").
						Funcs(sprigx.TxtFuncMap()).
						Parse(myTpl),
					).
					Funcs(sprig.TxtFuncMap())
)

and a function can even be explicitly overridden.

(show)

This would override a function foo and foo2 in sprigx from foo and foo2 from sprig, but leave all other sprig functions untouched.

package main

import (
	"text/template"

	"github.com/Masterminds/sprig/v3"
	"r00t2.io/goutils/tplx/sprigx"
)

const (
	myTpl string = `{{ "This is an example template string." | foo }}`
)

var (
	overrideFuncs template.FuncMap = sprig.TxtFuncMap()
	tpl *template.Template = template.Must(
					template.
						New("").
						Funcs(sprigx.TxtFuncMap()).
						Parse(myTpl),
					).
					Funcs(
						template.FuncMap(
							map[string]any{
								"foo": overrideFuncs["foo"],
								"foo2": overrideFuncs["foo2"],
							},
						),
					)
)

3. Functions

Expect this list to grow over time, and potentially more frequently than the sprigx functions.

Each function includes its function signature to indicate what types of arguments/parameters it accepts, what it returns, and if it may potentially return an error or not.

3.1. Debugging

3.1.1. dump

Function Signature
func dump(a ...interface{}) (out string)

The dump function directly calls github.com/davecgh/go-spew/spew.Sdump for whatever object(s) is/are passed to it.

3.2. "Meta"/Template Helpers

3.2.1. metaIsNil

Function Signature
func metaIsNil(obj any) (isNil bool)

metaIsNil returns true if obj is explicitly nil, otherwise it returns false.

This function fills in the gap that text/template.IsTrue and html/template.IsTrue (expressed in templates as {{ if …​ }}) leaves, as those functions/expressions return false for e.g. false booleans AND nils.

3.2.2. Nop

Function Signature
func Nop(obj ...any) (s string)

Nop is not actually a template function, but rather an exported Go function that one can use in an override map to explicitly disable certain template functions that may be deemed "unsafe" and/or to sanitize templates from untrusted input.

It will never error or panic, and s is always an empty string.

3.3. Operating System

3.3.1. osFQDN

Function Signature
func osFQDN() (fqdn string, err error)

osFQDN currently just directly calls os.Hostname.

As such, it comes with the same caveatsnamely that it isnt guaranteed to be an FQDN, it will be precisely/exactly whatever the kernel/OS hostname is set as.

In the future, it may be extended to support a more diligent effort to determine an actual FQDN, and return an error if it is unable to be derived.

To (relatively) predictably get the "short hostname", use osHost. To directly/predictably use os.Hostname, use osHostname.

3.3.2. osGroupById

Function Signature
func osGroupById[T string | int](gid T) (g *user.Group, err error)

osGroupById returns an os/user.Group from a given group ID/GID.

It more or less behaves exactly like os/user.LookupGroupId, except it will accept either a string or an int as the GID.

3.3.3. osGroupByName

Function Signature
func osGroupByName(grpNm string) (g *user.Group, err error)

osGroupByName returns an os/user.Group from a given group name.

It behaves exactly like os/user.LookupGroup.

3.3.4. osHost

Function Signature
func osHost() (out string, err error)

osHost returns the "short hostname" by calling os.Hostname and returning the first "host label" (as RFCs refer to it).

e.g.:

{{- $fqdn := osFQDN -}}
{{- $h := osHost -}}
{{- $cmp := index ($fqdn | splitList ".") 0 -}}
osHost {{ $h }} should be equal to first label of FQDN {{ $cmp }}.
Tip

The splitList function shown aboce is from the sprig string slice functions.

To (try to) get the FQDN, use osFQDN. To directly use os.Hostname, use osHostname.

3.3.5. osHostname

Function Signature
func osHostname() (out string, err error)

osHostname directly calls os.Hostname.

3.3.6. osIdState

Function Signature
func osIdState() (idst sysutils.IDState)

osIdState returns the current runtime process' r00t2.io/sysutils.IDState.

It directly calls r00t2.io/sysutils.GetIDState.

Warning

This is more or less useless on Windows; it returns only a dummy struct for cross-platform compatibility.

3.3.7. osUser

Function Signature
func osUser() (u *user.User, err error)

osUser returns the current runtime process' os/user.User.

It directly calls os/user.Current.

3.3.8. osUserById

Function Signature
func osUserById[T string | int](uid T) (u *user.User, err error)

osUserById returns an os/user.User from a given user ID/UID.

It more or less behaves exactly like os/user.LookupId, except it will accept either a string or an int as the UID.

3.3.9. osUserByName

Function Signature
func osUserByName(userNm string) (u *user.User, err error)

osUserByName returns an os/user.User from a given username.

It directly calls os/user.Lookup.

3.4. Paths

3.4.1. Generic

These operate similar to the path stdlib library and use a fixed / path separator.

3.4.1.1. pathJoin
Function Signature
func pathJoin(elem ...string) (out string)

pathJoin directly calls path.Join.

Warning

If you are joining paths in a pipeline, you almost assuredly want pathPipeJoin or pathSlicePipeJoin instead unless you are explicitly appending a pipeline result to a path.

{{- pathJoin "a" "b" "c" }}
{{- pathJoin "/" "a" "b" "c" }}
{{- pathJoin "/a/b" "c" }}

renders as:

a/b/c
/a/b/c
/a/b/c
3.4.1.2. pathPipeJoin
Function Signature
func pathPipeJoin(elems ...string) (out string)

pathPipeJoin operates like pathJoin with one deviation: the root/base path is expected to be last in the arguments.

This makes it much more suitable for use in template pipelines, as the previous value in a pipeline is passed in as the last element to the next pipe function.

{{- $myBase := "/a" -}}
{{- pathPipeJoin "b" "c" "a" }}
{{- pathPipeJoin "a" "b" "c" "/" }}
{{- $myBase | pathPipeJoin "b" "c" }}

renders as:

a/b/c
/a/b/c
/a/b/c
3.4.1.3. pathSliceJoin
Function Signature
func pathSliceJoin(sl []string) (out string)

pathSliceJoin joins a slice of path segment strings ([]string) instead of a variadic sequence of strings.

Tip

The splitList function shown below is from the sprig string slice functions.

{{- $myList := "a,b,c" | splitList "," -}}
{{- $myList | pathSliceJoin }}
{{- ("a,b,c" | splitList ",") | pathSliceJoin }}
{{- ("/,a,b,c" | splitList ",") | pathSliceJoin }}

renders as:

a/b/c
a/b/c
/a/b/c
3.4.1.4. pathSlicePipeJoin
Function Signature
func pathSlicePipeJoin(sl []string, root string) (out string)

pathSlicePipeJoin operates like pathPipeJoin in that it is suitable for pipeline use in which the root/base path is passed in from the pipeline, but it is like pathSliceJoin in that it then also accepts a slice of path segments ([]string) to append to that base path.

Tip

The splitList function shown below is from the sprig string slice functions.

{{- $myBase := "/a" -}}
{{- $myList := "b,c,d" | splitList "." -}}
{{- pathSlicePipeJoin $myList $myBase }}
{{- $myBase | pathSlicePipeJoin $myList }}

renders as:

/a/b/c
/a/b/c
3.4.1.5. pathSubJoin
Function Signature
func pathSubJoin(root string, elems ...string) (out string)

pathSubJoin operates like pathJoin but it expects an explicit root/base path.

The pipeline-friendly equivalent of this is pathPipeJoin.

{{- pathSubJoin "/a/b" "c" }}
{{- pathSubJoin "/" "a" "b" "c" }}
{{- "c" | pathSubJoin "/" "a" "b" }}

renders as:

/a/b/c
/a/b/c
/a/b/c

3.4.2. OS/Platform-Tailored

These operate similar to the path/filepath stdlib library, and use the OS-specific os.PathSeparator.

Warning

Take special note of the oddness around specifying Windows paths and drive letters in e.g. osPathJoin!

It is recommended to make use of sysOsName to conditionally format path bases/roots if needed.

3.4.2.1. osPathJoin
Function Signature
func osPathJoin(elem ...string) (out string)

osPathJoin directly calls path/filepath.Join.

Warning

If you are joining paths in a pipeline, you almost assuredly want osPathPipeJoin or osPathSlicePipeJoin instead unless you are explicitly appending a pipeline result to a path.

{{- osPathJoin "a" "b" "c" }}
{{- osPathJoin "/" "a" "b" "c" }}
{{- osPathJoin "C:\\" "a" "b" "c" }}
{{- osPathJoin "C:" "a" "b" "c" }}

renders as:

OS Result

Windows

a\b\c
\a\b\c
\a\b\c
C:\a\b\c
C:a\b\c

Others (e.g. Linux, macOS)

a/b/c
/a/b/c
C:\/a/b/c
C:/a/b/c
3.4.2.2. osPathPipeJoin
Function Signature
func osPathPipeJoin(elems ...string) (out string)

osPathPipeJoin operates like pathPipeJoin (except using OS-specific path separators).

This makes it much more suitable for use in template pipelines, as the previous value in a pipeline is passed in as the last argument to the next pipe function.

{{- $myBase := "/a" -}}
{{- osPathPipeJoin "b" "c" "a" }}
{{- osPathPipeJoin "a" "b" "c" "/" }}
{{- $myBase | osPathPipeJoin "b" "c" }}

renders as:

OS Result

Windows

a\b\c
\a\b\c
\a\b\c

Others (e.g. Linux, macOS)

a/b/c
/a/b/c
/a/b/c
3.4.2.3. osPathSep
Function Signature
func osPathSep() (out string)

osPathSep returns the os.PathSeparator for this OS.

{{- osPathSep }}

renders as:

OS Result

Windows

\

Others (e.g. Linux, macOS)

/
3.4.2.4. osPathSliceJoin
Function Signature
func osPathSliceJoin(sl []string) (out string)

osPathSliceJoin operates like pathSliceJoin but with OS-specific path separators.

Tip

The splitList function shown below is from the sprig string slice functions.

{{- $myList := "a,b,c" | splitList "," -}}
{{- $myList | osPathSliceJoin }}
{{- ("a,b,c" | splitList ",") | osPathSliceJoin }}
{{- ("/,a,b,c" | splitList ",") | osPathSliceJoin }}

renders as:

OS Result

Windows

a\b\c
a\b\c
\a\b\c

Others (e.g. Linux, macOS)

a/b/c
a/b/c
/a/b/c
3.4.2.5. osPathSlicePipeJoin
Function Signature
func osPathSlicePipeJoin(sl []string, root string) (out string)

osPathSlicePipeJoin operates like pathSlicePipeJoin but with OS-specific separators.

Tip

The splitList function shown below is from the sprig string slice functions.

{{- $myBase := "/a" -}}
{{- $myList := "b,c,d" | splitList "." -}}
{{- osPathSlicePipeJoin $myList $myBase }}
{{- $myBase | osPathSlicePipeJoin $myList }}

renders as:

OS Result

Windows

\a\b\c\d
\a\b\c\d

Others (e.g. Linux, macOS)

/a/b/c/d
/a/b/c/d
3.4.2.6. osPathSubJoin
Function Signature
func osPathSubJoin(root string, elems ...string) (out string)

osPathSubJoin operates like pathSubJoin but with OS-specific separators.

The pipeline-friendly equivalent of this is osPathPipeJoin.

{{- osPathSubJoin "/a/b" "c" }}
{{- osPathSubJoin "/" "a" "b" "c" }}
{{- "c" | osPathSubJoin "/" "a" "b" }}

renders as:

OS Result

Windows

\a\b\c
\a\b\c
\a\b\c

Others (e.g. Linux, macOS)

/a/b/c
/a/b/c
/a/b/c

3.5. PSUtils

These are functions from github.com/shirou/gopsutil/v4 packages.

3.5.1. CPU/Processor

3.5.1.1. psCpuCnts
Function Signature
func psCpuCnts(logical bool) (numCpu int, err error)

psCpuCnts directly calls github.com/shirou/gopsutil/v4/cpu.Counts.

3.5.1.2. psCpuInfo
Function Signature
func psCpuInfo() (cpuInfo [](github.com/shirou/gopsutil/v4/cpu).Info, err error)

psCpuInfo directly calls github.com/shirou/gopsutil/v4/cpu.Info.

3.5.1.3. psCpuPct
Function Signature
func psCpuPct(interval time.Duration, percpu bool) (pcts []float64, err error)
3.5.1.4. psCpuTimes
Function Signature
func psCpuTimes(percpu bool) (cpuTimes []TimesStat, err error)

psCpuTimes directly calls github.com/shirou/gopsutil/v4/cpu.Times.

3.5.2. Disk

3.5.2.1. psDiskIoCnts
Function Signature
func psDiskIoCnts(names ...string) (stats map[string]IOCountersStat, err error)

psDiskIoCnts directly calls github.com/shirou/gopsutil/v4/disk.IOCounters.

3.5.2.2. psDiskLabel
Function Signature
func psDiskLabel(name string) (label string, err error)

psDiskLabel directly calls github.com/shirou/gopsutil/v4/disk.Label.

3.5.2.3. psDiskParts
Function Signature
func psDiskParts(all bool) (parts [](github.com/shirou/gopsutil/v4/disk).PartitionStat, err error)

psDiskParts directly calls github.com/shirou/gopsutil/v4/disk.Partitions.

3.5.2.4. psDiskSerial
Function Signature
func psDiskSerial(name string) (serial string, err error)
3.5.2.5. psDiskUsage
Function Signature
func psDiskUsage(path string) (usage *(github.com/shirou/gopsutil/v4/disk).UsageStat, err error)

psDiskUsage directly calls github.com/shirou/gopsutil/v4/disk.Usage.

3.5.3. Host

3.5.3.1. psHostBoot
Function Signature
func psHostBoot() (bootEpoch uint64, err error)

psHostBoot directly calls github.com/shirou/gopsutil/v4/host.BootTime.

3.5.3.2. psHostId
Function Signature
func psHostId() (hostId string, err error)
3.5.3.3. psHostInfo
Function Signature
func psHostInfo() (info *(github.com/shirou/gopsutil/v4/host).InfoStat, err error)

psHostInfo directly calls github.com/shirou/gopsutil/v4/host.Info.

3.5.3.4. psHostKernArch
Function Signature
func psHostKernArch() (arch string, err error)

psHostKernArch directly calls github.com/shirou/gopsutil/v4/host.KernelArch.

3.5.3.5. psHostKernVer
Function Signature
func psHostKernVer() (ver string, err error)

psHostKernVer directly calls github.com/shirou/gopsutil/v4/host.KernelVersion.

3.5.3.6. psHostPlatInfo
Function Signature
func psHostPlatInfo() (platInfo [3]string, err error)

It is necessary to wrap because the function normally returns (string, string, string, error) but a template function may only return either a single value (of any type) or a single value of any type and an error, so the three string returns are consolidated into an ordered [3]string.

3.5.3.7. psHostPlatUptime
Function Signature
func psHostPlatUptime() (uptimeSecs uint64, err error)

psHostPlatUptime directly calls github.com/shirou/gopsutil/v4/host.Uptime.

3.5.3.8. psHostUsers
Function Signature
func psHostUsers() (users [](github.com/shirou/gopsutil/v4/host).UserStat, err error)

psHostUsers directly calls github.com/shirou/gopsutil/v4/host.Users.

3.5.3.9. psHostPlatVirt
Function Signature
func psHostVirt() (virtInfo [2]string, err error)

It is necessary to wrap because the function normally returns (string, string, error) but a template function may only return either a single value (of any type) or a single value of any type and an error, so the two string returns are consolidated into an ordered [2]string.

3.5.4. Load

3.5.4.1. psLoadAvg
Function Signature
func psLoadAvg() (avg *(github.com/shirou/gopsutil/v4/load).AvgStat, err error)

psLoadAvg directly calls github.com/shirou/gopsutil/v4/load.Avg.

3.5.4.2. psLoadMisc
Function Signature
func psLoadMisc() (misc *(github.com/shirou/gopsutil/v4/load).MiscStat, err error)

psLoadMisc directly calls github.com/shirou/gopsutil/v4/load.Misc.

3.5.5. Memory

3.5.5.1. psMemExVMem
Function Signature
func psMemExVMem() (exVMem *(github.com/shirou/gopsutil/v4/mem).ExVirtualMemory, err error)
Warning

This function is available on Windows and Linux platforms only.

Warning

This function returns very different types depending on platform.

3.5.5.2. psMemSwap
Function Signature
func psMemSwap() (swap *(github.com/shirou/gopsutil/v4/mem).SwapMemoryStat, err error)
3.5.5.3. psMemSwapDevs
Function Signature
func psMemSwapDevs() (swapDevs []*(github.com/shirou/gopsutil/v4/mem).SwapDevice, err error)

psMemSwapDevs directly calls github.com/shirou/gopsutil/v4/mem.SwapDevices.

3.5.5.4. psMemVMem
Function Signature
func psMemVMem() (vmem *(github.com/shirou/gopsutil/v4/mem).VirtualMemoryStat, err error)

3.5.6. Network

3.5.6.1. psNetConns
Function Signature
func psNetConns(kind string) (conns [](github.com/shirou/gopsutil/v4/net).ConnectionStat, err error)
3.5.6.2. psNetConnsMax
Function Signature
func psNetConnsMax(kind string, maxConn int) (conns [](github.com/shirou/gopsutil/v4/net).ConnectionStat, err error)

psNetConnsMax directly calls github.com/shirou/gopsutil/v4/net.ConnectionsMax.

3.5.6.3. psNetConnsPid
Function Signature
func psNetConnsPid(kind string, pid int32) (conns [](github.com/shirou/gopsutil/v4/net).ConnectionStat, err error)

psNetConnsPid directly calls github.com/shirou/gopsutil/v4/net.ConnectionsPid.

3.5.6.4. psNetConnsPidMax
Function Signature
func psNetConnsPidMax(kind string, pid int32, maxConn int) (conns [](github.com/shirou/gopsutil/v4/net).ConnectionStat, err error)

psNetConnsPidMax directly calls github.com/shirou/gopsutil/v4/net.ConnectionsPidMax.

3.5.6.5. psNetCTStats
Function Signature
func psNetCTStats(percCpu bool) (ctStats [](github.com/shirou/gopsutil/v4/net).ConntrackStat, err error)
3.5.6.6. psNetCTStatList
Function Signature
func psNetCTStatList() (ctStats *(github.com/shirou/gopsutil/v4/net).ConntrackStatList, err error)

psNetCTStatList directly calls github.com/shirou/gopsutil/v4/net.ConntrackStatList.

3.5.6.7. psNetFilterCnts
Function Signature
func psNetFilterCnts() (filterCnts [](github.com/shirou/gopsutil/v4/net).FilterStat, err error)

psNetFilterCnts directly calls github.com/shirou/gopsutil/v4/net.FilterCounters.

3.5.6.8. psNetIoCnts
Function Signature
func psNetIoCnts(perNIC bool) (ioCnts [](github.com/shirou/gopsutil/v4/net).IOCountersStat, err error)

psNetIoCnts directly calls github.com/shirou/gopsutil/v4/net.IOCounters.

3.5.6.9. psNetIoCntsFile
Function Signature
func psNetIoCntsFile(perNIC bool, filepath string) (ioCnts [](github.com/shirou/gopsutil/v4/net).IOCountersStat, err error)

psNetIoCntsFile directly calls github.com/shirou/gopsutil/v4/net.IOCountersByFile.

3.5.6.10. psNetIfaces
Function Signature
func psNetIfaces() (ioCnts [](github.com/shirou/gopsutil/v4/net).InterfaceStatList, err error)

psNetIfaces directly calls github.com/shirou/gopsutil/v4/net.Interfaces.

3.5.6.11. psNetPids
Function Signature
func psNetPids() (pids []int32, err error)

psNetPids directly calls github.com/shirou/gopsutil/v4/net.Pids.

3.5.6.12. psNetProtoCnt
Function Signature
func psNetProtoCnt(protos []string) (protoCnts [](github.com/shirou/gopsutil/v4/net).ProtoCountersStat, err error)
Warning

This only works properly on Linux currently per upstream.

psNetProtoCnt directly calls github.com/shirou/gopsutil/v4/net.ProtoCounters.

3.5.6.13. psNetRev
Function Signature
func psNetRev(b []byte) (out []byte)
Warning

This function only exists on Linux.

3.5.7. Processes

3.5.7.1. psProcs
Function Signature
func psProcs(pid int32) (procs []*(github.com/shirou/gopsutil/v4/process).Process, err error)
3.5.7.2. psProcNew
Function Signature
func psProcNew(pid int32) (proc *(github.com/shirou/gopsutil/v4/process).Process, err error)
3.5.7.3. psProcPids
Function Signature
func psProcPids() (pids []int32, err error)

psProcPids directly calls github.com/shirou/gopsutil/v4/proc.Pids.

3.5.7.4. psProcPidExists
Function Signature
func psProcPidExists(pid int32) (exists bool, err error)

psProcPidExists directly calls github.com/shirou/gopsutil/v4/proc.PidExists.

3.5.8. Sensors/Thermals

3.5.8.1. psSensorExTemp
Function Signature
func psSensorExTemp() (temps [](github.com/shirou/gopsutil/v4/sensors).ExTemperature, err error)
Warning

This function only exists on Linux.

3.5.8.2. psSensorTemps
Function Signature
func psSensorTemps() (temps [](github.com/shirou/gopsutil/v4/sensors).TemperatureStat, err error)

3.5.9. Windows Services

Warning

All of these functions are only available on Windows.

3.5.9.1. psWinsvcList
Function Signature
func psWinsvcList() (svcs [](github.com/shirou/gopsutil/v4/winservices).Service, err error)
Warning

This function is only available on Windows.

3.5.9.2. psWinsvcNew
Function Signature
func psWinsvcNew(svcName string) (svc *(github.com/shirou/gopsutil/v4/winservices).Service, err error)
Warning

This function is only available on Windows.

3.6. Strings

3.6.1. extIndent

Function Signature
func extIndent(
		levels int,
		skipFirst, skipEmpty, skipWhitespace bool,
		indentString, input string,
	) (out string)

extIndent allows for a MUCH more flexible indenter than the sprig indent function.

It works with both Windows (\r\n) and POSIX (\n) linebreaks.

Tip

If <indentString> is set to \n and <levels> is always set to 1, this function can even be used to doubelspace text!

It has quite a few arguments, however:

{{ extIndent <levels> <skipFirst> <skipEmpty> <skipWhitespace> <indentString> <input> }}

Where:

  • <levels>: The level of indentation for the text. If less than or equal to 0, extIndent just returns <input> as-is and NO-OPs otherwise.

  • <skipFirst>: If true, skip indenting the first line. This is particularly handy if you like to visually align your function calls in your templates.

  • <skipEmpty>: If true, do not add an indent to empty lines (where an "empty line" means "only has a linebreak").

  • <skipWhitespace>: If true, do not add an indent to lines that only consist of whitespace (spaces, tabs, etc.) and a linebreak.

  • <indentString>: The string to use as the "indent character". This can be any string, such as " ", "\t", ".", "|", "==" etc.

  • <input>: The text to be indented. Because it is the last argument, extIndent works with pipelined text as well.

3.7. System/Platform/Architecture

3.7.1. sysArch

Function Signature
func sysArch() (out string)

Returns the runtime.GOARCH constant.

3.7.2. sysNumCpu

Function Signature
func sysNumCpu() (cnt int)

sysNumCpu directly calls runtime.NumCPU.

3.7.3. sysOsName

Function Signature
func sysOsNm() (out string)

Returns the runtime.GOOS constant.

3.7.4. sysRuntime

Function Signature
func sysRuntime() (out map[string]string)

This function returns a map[string]string of various information from the runtime stdlib library.

Specifically, the following are returned.

Tip

The value type is a direct link to the runtime documentation providing more detail about the associated value.

Because all values are mapped as strings, they can be converted back to their native type via e.g. the Sprig conversion functions if necessary.

Table 1. sysRuntime Values
Key Value Type

compiler

string

arch

string

os

string

maxprocs

int [1]

cpu_cnt

int

num_cgo

int

num_go

int

go_ver

string

As a convenience, some of these values also have their own dedicated functions as well:


1. For safety concerns, sprigx does not allow setting GOMAXPROCS, this value only contains the current GOMAXPROCS value.