Files
go_goutils/tplx/sprigx/consts.go
brent saner 07e0e587fa v1.16.4
ADDED:
* math, time functions to tplx/sprigx
FIXED:
* logging not initializing properly on some BSDs
2026-01-30 06:35:23 -05:00

154 lines
4.3 KiB
Go

package sprigx
import (
`os`
`os/user`
`path`
`path/filepath`
`runtime`
`time`
`github.com/davecgh/go-spew/spew`
`github.com/shirou/gopsutil/v4/cpu`
`github.com/shirou/gopsutil/v4/disk`
`github.com/shirou/gopsutil/v4/host`
`github.com/shirou/gopsutil/v4/load`
`github.com/shirou/gopsutil/v4/mem`
psnet `github.com/shirou/gopsutil/v4/net`
`github.com/shirou/gopsutil/v4/process`
`github.com/shirou/gopsutil/v4/sensors`
`r00t2.io/goutils/timex`
`r00t2.io/sysutils`
)
var (
// genericMap holds functions usable/intended for use in either an [html/template.FuncMap] or [text/template.FuncMap].
genericMap map[string]any = map[string]any{
// Debugging
"dump": spew.Sdump,
/*
"Meta"/Template-Helpers
*/
"metaIsNil": metaIsNil,
/*
Numbers/Math
*/
"numFloat32Str": numFloat32Str,
"numFloat64": numFloat64,
"numFloat64Str": numFloat64Str,
"numFloatStr": numFloatStr,
/*
OS
*/
"osFQDN": osFQDN,
"osGroupById": osGroupById,
"osGroupByName": user.LookupGroup,
"osHost": osHost,
"osHostname": os.Hostname,
"osIdState": sysutils.GetIDState,
"osUser": user.Current,
"osUserById": osUserById,
"osUserByName": user.Lookup,
/*
Paths
*/
// Paths: Generic
"pathJoin": path.Join,
"pathPipeJoin": pathPipeJoin,
"pathSliceJoin": pathSliceJoin,
"pathSlicePipeJoin": pathSlicePipeJoin,
"pathSubJoin": pathSubJoin,
// Paths: OS/Platform
"osPathJoin": filepath.Join,
"osPathPipeJoin": osPathPipeJoin,
"osPathSep": osPathSep,
"osPathSliceJoin": osPathSliceJoin,
"osPathSlicePipeJoin": osPathSlicePipeJoin,
"osPathSubJoin": osPathSubJoin,
/*
PSUtil
(https://pkg.go.dev/github.com/shirou/gopsutil/v4)
*/
// .../cpu
"psCpuCnts": cpu.Counts,
"psCpuInfo": cpu.Info,
"psCpuPct": cpu.Percent,
"psCpuTimes": cpu.Times,
// .../disk
"psDiskIoCnts": disk.IOCounters,
"psDiskLabel": disk.Label,
"psDiskParts": disk.Partitions,
"psDiskSerial": disk.SerialNumber,
"psDiskUsage": disk.Usage,
// .../host
"psHostBoot": host.BootTime,
"psHostId": host.HostID,
"psHostInfo": host.Info,
"psHostKernArch": host.KernelArch,
"psHostKernVer": host.KernelVersion,
"psHostPlatInfo": psHostPlatInfo,
"psHostUptime": host.Uptime,
"psHostUsers": host.Users,
"psHostVirt": psHostVirt,
// .../load
"psLoadAvg": load.Avg,
"psLoadMisc": load.Misc,
// .../mem
"psMemSwap": mem.SwapMemory,
"psMemSwapDevs": mem.SwapDevices,
"psMemVMem": mem.VirtualMemory,
// .../net
"psNetConns": psnet.Connections,
"psNetConnsMax": psnet.ConnectionsMax,
"psNetConnsPid": psnet.ConnectionsPid,
"psNetConnsPidMax": psnet.ConnectionsPidMax,
"psNetCTStats": psnet.ConntrackStats,
"psNetCTStatList": psnet.NewConntrackStatList,
"psNetFilterCnts": psnet.FilterCounters,
"psNetIoCnts": psnet.IOCounters,
"psNetIoCntsFile": psnet.IOCountersByFile,
"psNetIfaces": psnet.Interfaces,
"psNetPids": psnet.Pids,
"psNetProtoCnt": psnet.ProtoCounters,
// .../process
"psProcs": process.Processes,
"psProcNew": process.NewProcess,
"psProcPids": process.Pids,
"psProcPidExists": process.PidExists,
// .../sensors
"psSensorTemps": sensors.SensorsTemperatures,
/*
Strings
*/
"extIndent": extIndent, // PR in: https://github.com/Masterminds/sprig/pull/468
/*
System/Platform
*/
"sysArch": sysArch,
"sysNumCpu": runtime.NumCPU,
"sysOsName": sysOsNm,
"sysRuntime": sysRuntime,
/*
Time/Dates/Timestamps
*/
"tmDate": time.Date,
"tmFmt": tmFmt,
"tmFloatMicro": timex.F64Microseconds,
"tmFloatMilli": timex.F64Milliseconds,
"tmFloatNano": timex.F64Nanoseconds,
"tmFloat": timex.F64Seconds,
"tmNow": time.Now,
"tmParseDur8n": time.ParseDuration,
"tmParseMonth": tmParseMonth,
"tmParseMonthInt": tmParseMonthInt,
"tmParseMonthStr": tmParseMonthStr,
"tmParseTime": time.Parse,
}
// htmlMap holds functions usable/intended for use in only an [html/template.FuncMap].
htmlMap map[string]any = map[string]any{}
// txtMap holds functions usable/intended for use in only a [text/template.FuncMap].
txtMap map[string]any = map[string]any{}
)