SprigX
bts@square-r00t.net
Last rendered 2026-01-30 20:21:34 -0500
Table of Contents
- 1. What is SprigX?
- 2. How do I Use SprigX?
- 3. Library Functions
- 4. Template Functions
- 4.1. Debugging
- 4.2. "Meta"/Template Helpers
- 4.3. Numbers/Math
- 4.4. Operating System
- 4.5. Paths
- 4.6. PSUtil
- 4.7. Strings
- 4.8. Time/Dates/Timestamps
- 4.9. System/Platform/Architecture
1. What is SprigX?
SprigX is a suite of 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(),
)
*/
Or, as a convenience, you can simply use the
sprigx.CombinedTxtFuncMap and/or
sprigx.CombinedHtmlFuncMap functions.
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. Library Functions
These are generally intended to be used outside the template in the actual Go code.
3.1.
Function Signature
func CombinedFuncMap(preferSprigX bool) (fmap map[string]any)
This function returns a generic function map (like
FuncMap) combined with github.com/Masterminds/sprig/v3.GenericFuncMap.
If preferSprigx is true, SprigX function names will override Sprig
functions with the same name. If false, Sprig functions will override
conflicting SprigX functions with the same name.
You probably want CombinedTxtFuncMap or
CombinedHtmlFuncMap instead, as they wrap this with
the appropriate type.
3.2.
Function Signature
func CombinedHtmlFuncMap(preferSprigX bool) (fmap (html/template).FuncMap)
This function returns an
(html/template).FuncMap
function map (like HtmlFuncMap) combined with
github.com/Masterminds/sprig/v3.HtmlFuncMap.
If preferSprigx is true, SprigX function names will override Sprig
functions with the same name. If false, Sprig functions will override
conflicting SprigX functions with the same name.
3.3.
Function Signature
func CombinedTxtFuncMap(preferSprigX bool) (fmap (text/template).FuncMap)
This function returns a
(text/template).FuncMap
function map (like TxtFuncMap) combined with
github.com/Masterminds/sprig/v3.TxtFuncMap.
If preferSprigx is true, SprigX function names will override Sprig
functions with the same name. If false, Sprig functions will override
conflicting SprigX functions with the same name.
3.4. FuncMap
Function Signature
func FuncMap() (fmap map[string]any)
This function returns a generic SprigX function map.
You probably want TxtFuncMap or
HtmlFuncMap instead, as they wrap this with the
appropriate type.
3.5. HtmlFuncMap
Function Signature
func HtmlFuncMap() (fmap (html/template).FuncMap)
This function returns a SprigX
(html/template).FuncMap.
3.6. Nop
Function Signature
func Nop(obj ...any) (s string)
Nop is a NO-OP function that one can use in an override
map to explicitly disable certain Sprig/SprigX 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.7. TxtFuncMap
Function Signature
func TxtFuncMap() (fmap (text/template).FuncMap)
This function returns a SprigX
(text/template).FuncMap.
4. Template 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.
4.1. Debugging
4.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.
4.2. "Meta"/Template Helpers
4.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.
4.3. Numbers/Math
4.3.1.
Function Signature
func numFloat32Str(f float32) (s string)
numFloat32Str returns a complete non-truncated non-right-padded
string representation of a float32.
4.3.2. numFloat64
Function Signature
func numFloat64(val any) (f float64, err error)
numFloat64 returns any string representation of a numeric value or any
type of numeric value to a float64.
4.3.3.
Function Signature
func numFloat64Str(f float64) (s string)
numFloat64Str returns a complete non-truncated non-right-padded
string representation of a float64.
4.3.4. numFloatStr
Function Signature
func numFloatStr(val any) (s string, err error)
numFloatStr wraps numFloat32Str and
numFloat64Str.
val can be a string representation of any numeric value or any type of
numeric value.
4.4. Operating System
4.4.1. osFQDN
Function Signature
func osFQDN() (fqdn string, err error)
osFQDN currently just directly calls
os.Hostname.
As such, it comes with the same caveats — namely that it isn’t 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.
4.4.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.
4.4.3.
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.
4.4.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 |
To (try to) get the FQDN, use osFQDN. To directly use
os.Hostname, use
osHostname.
4.4.5. osHostname
Function Signature
func osHostname() (out string, err error)
osHostname directly calls
os.Hostname.
4.4.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. |
4.4.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.
4.4.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.
4.4.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.
4.5. Paths
4.5.1. Generic
These operate similar to
the
path stdlib library and use a fixed / path separator.
4.5.1.1.
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 |
{{- pathJoin "a" "b" "c" }}
{{- pathJoin "/" "a" "b" "c" }}
{{- pathJoin "/a/b" "c" }}
renders as:
a/b/c
/a/b/c
/a/b/c
4.5.1.2.
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
4.5.1.3.
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 |
{{- $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
4.5.1.4.
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 |
{{- $myBase := "/a" -}}
{{- $myList := "b,c,d" | splitList "." -}}
{{- pathSlicePipeJoin $myList $myBase }}
{{- $myBase | pathSlicePipeJoin $myList }}
renders as:
/a/b/c
/a/b/c
4.5.1.5.
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
4.5.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. It is recommended to make use of |
4.5.2.1.
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 |
{{- osPathJoin "a" "b" "c" }}
{{- osPathJoin "/" "a" "b" "c" }}
{{- osPathJoin "C:\\" "a" "b" "c" }}
{{- osPathJoin "C:" "a" "b" "c" }}
renders as:
| OS | Result |
|---|---|
Windows |
|
Others (e.g. Linux, macOS) |
|
4.5.2.2.
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 |
|
Others (e.g. Linux, macOS) |
|
4.5.2.3.
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) |
|
4.5.2.4.
Function Signature
func osPathSliceJoin(sl []string) (out string)
osPathSliceJoin operates like pathSliceJoin but
with OS-specific path separators.
Tip
|
The |
{{- $myList := "a,b,c" | splitList "," -}}
{{- $myList | osPathSliceJoin }}
{{- ("a,b,c" | splitList ",") | osPathSliceJoin }}
{{- ("/,a,b,c" | splitList ",") | osPathSliceJoin }}
renders as:
| OS | Result |
|---|---|
Windows |
|
Others (e.g. Linux, macOS) |
|
4.5.2.5.
Function Signature
func osPathSlicePipeJoin(sl []string, root string) (out string)
osPathSlicePipeJoin operates like
pathSlicePipeJoin but with OS-specific
separators.
Tip
|
The |
{{- $myBase := "/a" -}}
{{- $myList := "b,c,d" | splitList "." -}}
{{- osPathSlicePipeJoin $myList $myBase }}
{{- $myBase | osPathSlicePipeJoin $myList }}
renders as:
| OS | Result |
|---|---|
Windows |
|
Others (e.g. Linux, macOS) |
|
4.5.2.6.
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 |
|
Others (e.g. Linux, macOS) |
|
4.6. PSUtil
These are functions from
github.com/shirou/gopsutil/v4 packages.
4.6.1. CPU/Processor
4.6.1.1.
Function Signature
func psCpuCnts(logical bool) (numCpu int, err error)
psCpuCnts directly calls
github.com/shirou/gopsutil/v4/cpu.Counts.
4.6.1.2.
Function Signature
func psCpuInfo() (cpuInfo [](github.com/shirou/gopsutil/v4/cpu).Info, err error)
psCpuInfo directly calls
github.com/shirou/gopsutil/v4/cpu.Info.
4.6.1.3. psCpuPct
Function Signature
func psCpuPct(interval time.Duration, percpu bool) (pcts []float64, err error)
psCpuPct directly calls
github.com/shirou/gopsutil/v4/cpu.Percent.
4.6.1.4.
Function Signature
func psCpuTimes(percpu bool) (cpuTimes []TimesStat, err error)
psCpuTimes directly calls
github.com/shirou/gopsutil/v4/cpu.Times.
4.6.2. Disk
4.6.2.1.
Function Signature
func psDiskIoCnts(names ...string) (stats map[string]IOCountersStat, err error)
psDiskIoCnts directly calls github.com/shirou/gopsutil/v4/disk.IOCounters.
4.6.2.2.
Function Signature
func psDiskLabel(name string) (label string, err error)
psDiskLabel directly calls
github.com/shirou/gopsutil/v4/disk.Label.
4.6.2.3.
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.
4.6.2.4.
Function Signature
func psDiskSerial(name string) (serial string, err error)
psDiskSerial directly calls github.com/shirou/gopsutil/v4/disk.SerialNumber.
4.6.2.5.
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.
4.6.3. Host
4.6.3.1.
Function Signature
func psHostBoot() (bootEpoch uint64, err error)
psHostBoot directly calls
github.com/shirou/gopsutil/v4/host.BootTime.
4.6.3.2. psHostId
Function Signature
func psHostId() (hostId string, err error)
psHostId directly calls
github.com/shirou/gopsutil/v4/host.HostID.
4.6.3.3.
Function Signature
func psHostInfo() (info *(github.com/shirou/gopsutil/v4/host).InfoStat, err error)
psHostInfo directly calls
github.com/shirou/gopsutil/v4/host.Info.
4.6.3.4.
Function Signature
func psHostKernArch() (arch string, err error)
psHostKernArch directly calls github.com/shirou/gopsutil/v4/host.KernelArch.
4.6.3.5.
Function Signature
func psHostKernVer() (ver string, err error)
psHostKernVer directly calls github.com/shirou/gopsutil/v4/host.KernelVersion.
4.6.3.6.
Function Signature
func psHostPlatInfo() (platInfo [3]string, err error)
psHostPlatInfo wraps github.com/shirou/gopsutil/v4/host.PlatformInformation.
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.
4.6.3.7.
Function Signature
func psHostPlatUptime() (uptimeSecs uint64, err error)
psHostPlatUptime directly calls
github.com/shirou/gopsutil/v4/host.Uptime.
4.6.3.8.
Function Signature
func psHostUsers() (users [](github.com/shirou/gopsutil/v4/host).UserStat, err error)
psHostUsers directly calls
github.com/shirou/gopsutil/v4/host.Users.
4.6.3.9.
Function Signature
func psHostVirt() (virtInfo [2]string, err error)
psHostPlatVirt wraps github.com/shirou/gopsutil/v4/host.Virtualization.
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.
4.6.4. Load
4.6.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.
4.6.4.2.
Function Signature
func psLoadMisc() (misc *(github.com/shirou/gopsutil/v4/load).MiscStat, err error)
psLoadMisc directly calls
github.com/shirou/gopsutil/v4/load.Misc.
4.6.5. Memory
4.6.5.1.
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.
|
This function wraps
github.com/shirou/gopsutil/v4/mem.NewExLinux
.VirtualMemory
on Linux and
github.com/shirou/gopsutil/v4/mem.NewExWindows
.VirtualMemory
on Windows.
4.6.5.2.
Function Signature
func psMemSwap() (swap *(github.com/shirou/gopsutil/v4/mem).SwapMemoryStat, err error)
psMemSwap directly calls github.com/shirou/gopsutil/v4/mem.SwapMemory.
4.6.5.3.
Function Signature
func psMemSwapDevs() (swapDevs []*(github.com/shirou/gopsutil/v4/mem).SwapDevice, err error)
psMemSwapDevs directly calls github.com/shirou/gopsutil/v4/mem.SwapDevices.
4.6.5.4.
Function Signature
func psMemVMem() (vmem *(github.com/shirou/gopsutil/v4/mem).VirtualMemoryStat, err error)
psMemVMem directly calls github.com/shirou/gopsutil/v4/mem.VirtualMemory.
4.6.6. Network
4.6.6.1.
Function Signature
func psNetConns(kind string) (conns [](github.com/shirou/gopsutil/v4/net).ConnectionStat, err error)
psNetConns directly calls github.com/shirou/gopsutil/v4/net.Connections.
4.6.6.2.
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.
4.6.6.3.
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.
4.6.6.4.
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.
4.6.6.5.
Function Signature
func psNetCTStats(percCpu bool) (ctStats [](github.com/shirou/gopsutil/v4/net).ConntrackStat, err error)
psNetCTStats directly calls github.com/shirou/gopsutil/v4/net.ConntrackStats.
4.6.6.6.
Function Signature
func psNetCTStatList() (ctStats *(github.com/shirou/gopsutil/v4/net).ConntrackStatList, err error)
psNetCTStatList directly calls github.com/shirou/gopsutil/v4/net.ConntrackStatList.
4.6.6.7.
Function Signature
func psNetFilterCnts() (filterCnts [](github.com/shirou/gopsutil/v4/net).FilterStat, err error)
psNetFilterCnts directly calls github.com/shirou/gopsutil/v4/net.FilterCounters.
4.6.6.8.
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.
4.6.6.9.
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.
4.6.6.10.
Function Signature
func psNetIfaces() (ioCnts [](github.com/shirou/gopsutil/v4/net).InterfaceStatList, err error)
psNetIfaces directly calls github.com/shirou/gopsutil/v4/net.Interfaces.
4.6.6.11.
Function Signature
func psNetPids() (pids []int32, err error)
psNetPids directly calls
github.com/shirou/gopsutil/v4/net.Pids.
4.6.6.12.
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.
4.6.6.13.
Function Signature
func psNetRev(b []byte) (out []byte)
Warning
|
This function only exists on Linux. |
psNetRev directly calls github.com/shirou/gopsutil/v4/net.Reverse.
4.6.7. Processes
4.6.7.1.
Function Signature
func psProcs(pid int32) (procs []*(github.com/shirou/gopsutil/v4/process).Process, err error)
psProcs directly calls github.com/shirou/gopsutil/v4/proc.Processes.
4.6.7.2.
Function Signature
func psProcNew(pid int32) (proc *(github.com/shirou/gopsutil/v4/process).Process, err error)
psProcNew directly calls github.com/shirou/gopsutil/v4/proc.NewProcess.
4.6.7.3.
Function Signature
func psProcPids() (pids []int32, err error)
psProcPids directly calls
github.com/shirou/gopsutil/v4/proc.Pids.
4.6.7.4.
Function Signature
func psProcPidExists(pid int32) (exists bool, err error)
psProcPidExists directly calls github.com/shirou/gopsutil/v4/proc.PidExists.
4.6.8. Sensors/Thermals
4.6.8.1.
Function Signature
func psSensorExTemp() (temps [](github.com/shirou/gopsutil/v4/sensors).ExTemperature, err error)
Warning
|
This function only exists on Linux. |
psSensorExTemp wraps
github.com/shirou/gopsutil/v4/sensors.NewExLinux
.github.com/shirou/gopsutil/v4/sensors.TemperatureWithContext.
4.6.8.2.
Function Signature
func psSensorTemps() (temps [](github.com/shirou/gopsutil/v4/sensors).TemperatureStat, err error)
psSensorTemps directly calls github.com/shirou/gopsutil/v4/sensors.SensorsTemperatures.
4.6.9. Windows Services
Warning
|
All of these functions are only available on Windows. |
4.6.9.1.
Function Signature
func psWinsvcList() (svcs [](github.com/shirou/gopsutil/v4/winservices).Service, err error)
Warning
|
This function is only available on Windows. |
psWinsvcList directly calls github.com/shirou/gopsutil/v4/winservices.ListServices.
4.6.9.2.
Function Signature
func psWinsvcNew(svcName string) (svc *(github.com/shirou/gopsutil/v4/winservices).Service, err error)
Warning
|
This function is only available on Windows. |
psWinsvcNew directly calls github.com/shirou/gopsutil/v4/winservices.NewService.
4.7. Strings
4.7.1.
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 |
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 to0,extIndentjust 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,extIndentworks with pipelined text as well.
4.8. Time/Dates/Timestamps
Note
|
Some of these functions duplicate Sprig functionality, but are included here for predictable API. Care has been taken to name these functions differently from the Sprig functions where possible and sensible. |
4.8.1. tmDate
Function Signature
func tmDate(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) (date time.Time)
tmDate directly calls
time.Date.
4.8.2.
Function Signature
func tmFloatMicro(t time.Time) (f64 float64)
tmFloatMicro directly calls
(r00t2.io/goutils/timex).F64Microseconds.
4.8.3.
Function Signature
func tmFloatMilli(t time.Time) (f64 float64)
tmFloatMilli directly calls
(r00t2.io/goutils/timex).F64Milliseconds.
4.8.4.
Function Signature
func tmFloatNano(t time.Time) (f64 float64)
tmFloatNano directly calls
(r00t2.io/goutils/timex).F64Nanoseconds.
4.8.5. tmFloat
Function Signature
func tmFloat(t time.Time) (f64 float64)
tmFloat directly calls
(r00t2.io/goutils/timex).F64Seconds.
4.8.6. tmFmt
Function Signature
func tmFmt(fstr string, t time.Time) (out string)
tmFormat provides a more pipeline-friendly alternative to calling e.g.
{{- $t := tmNow -}}
{{ $t.Format "<some time format string>" }}
4.8.8.
Function Signature
func tmParseDur8n(s string) (d time.Duration, err error)
tmParseDur8n directly calls
time.ParseDuration.
4.8.9. tmParseMonth
Function Signature
func tmParseMonth(v any) (mon time.Month, err error)
tmParseMonth attempts to first try tmParseMonthInt
and then tries tmParseMonthStr if v is not
"numeric".
4.8.10.
Function Signature
func tmParseMonthInt(n any) (mon time.Month, err error)
tmParseMonthInt parses a number representation of month n to a
time.Month. n may be any numeric type
or a string representation of a number (or a custom type derived from
those).
A negative integer (or float, etc.) will be converted to a positive one
(e.g. -6 → 6 → time.June).
Floats are rounded to the nearest integer.
The integer should map directly to the
time.Month constants in the time
module:
-
1:time.January -
2:time.February -
3:time.March -
4:time.April -
5:time.May -
6:time.June -
7:time.July -
8:time.August -
9:time.September -
10:time.October -
11:time.November -
12:time.December
If n resolves to 0, mon will be the current month (as determined
by time.Now).
If n resolves to > 12, err will be sprigx.ErrBadMonth (though
be sure to use errors.Is; it will be wrapped by
(text/template).ExecError/(html/template).ExecError.
4.8.11.
Function Signature
func tmParseMonthStr(s string) (mon time.Month, err error)
tmParseMonthStr parses a string representation s of a month to a
time.Month.
It normalizes s to lowercase and only uses the first 3 characters (the
minimum length needed to determine month name uniqueness - "June" vs.
"July", "March" vs. "May").
An empty (or whitespace-only) string will use the current month (as
determined by time.Now).`
4.8.12. tmParseTime
Function Signature
func tmParseTime(layout, value string) (t time.Time, err error)
tmParseTime directly calls
time.Parse.
Be sure that layout is a properly parseable
layout format.
4.9. System/Platform/Architecture
4.9.2. sysNumCpu
Function Signature
func sysNumCpu() (cnt int)
sysNumCpu directly calls
runtime.NumCPU.
4.9.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 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. |
| Key | Value Type |
|---|---|
compiler |
<a href="https://pkg.go.dev/runtime#Compiler" target="_blank" |
| rel="noopener">string | |
arch |
<a href="https://pkg.go.dev/runtime#GOARCH" target="_blank" |
| rel="noopener">string | |
os |
<a href="https://pkg.go.dev/runtime#GOOS" target="_blank" |
| rel="noopener">string | |
maxprocs |
<a href="https://pkg.go.dev/runtime#GOMAXPROCS" target="_blank" |
| rel="noopener">int [<a href="#_footnotedef_1" id="_footnoteref_1" class="footnote" | |
| title="View footnote.">1] | |
cpu_cnt |
<a href="https://pkg.go.dev/runtime#NumCPU" target="_blank" |
| rel="noopener">int | |
num_cgo |
<a href="https://pkg.go.dev/runtime#NumCgoCall" target="_blank" |
| rel="noopener">int | |
num_go |
<a href="https://pkg.go.dev/runtime#NumGoroutine" target="_blank" |
| rel="noopener">int | |
go_ver |
<a href="https://pkg.go.dev/runtime#Version" target="_blank" |
| rel="noopener">string |
Table 1. sysRuntime Values
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.