ADDED:
* math, time functions to tplx/sprigx
FIXED:
* logging not initializing properly on some BSDs
This commit is contained in:
brent saner
2026-01-30 06:35:23 -05:00
parent 1bd6e1256c
commit 07e0e587fa
16 changed files with 6831 additions and 260 deletions

View File

@@ -7,16 +7,29 @@ import (
`strings`
)
// osGroupById returns os/user.LookupGroupId. Can accept either an integer or a string.
func osGroupById[T string | int](gid T) (g *user.Group, err error) {
/*
osGroupById returns os/user.LookupGroupId.
Can accept either a string (`"1000"`) or any
numeric type (`1000`, `-1000`, `1000.0`, `MyCustomType(1000)`, etc.)
*/
func osGroupById(gid any) (g *user.Group, err error) {
var i int
var NaN bool
var gidStr string
switch t := any(gid).(type) {
case string:
gidStr = t
case int:
gidStr = strconv.Itoa(t)
if i, NaN, err = toPosInt(gid); err != nil {
if NaN {
err = nil
if gidStr, err = toString(gid); err != nil {
return
}
} else {
return
}
} else {
gidStr = strconv.Itoa(i)
}
g, err = user.LookupGroupId(gidStr)
@@ -55,16 +68,29 @@ func osHost() (hostNm string, err error) {
return
}
// osUserById returns an os/user.LookupId. Can accept either an integer or a string.
func osUserById[T string | int](uid T) (u *user.User, err error) {
/*
osUserById returns an os/user.LookupId.
Can accept either a string (`"1000"`) or any
numeric type (`1000`, `-1000`, `1000.0`, `MyCustomType(1000)`, etc.)
*/
func osUserById(uid any) (u *user.User, err error) {
var i int
var NaN bool
var uidStr string
switch t := any(uid).(type) {
case string:
uidStr = t
case int:
uidStr = strconv.Itoa(t)
if i, NaN, err = toPosInt(uid); err != nil {
if NaN {
err = nil
if uidStr, err = toString(uid); err != nil {
return
}
} else {
return
}
} else {
uidStr = strconv.Itoa(i)
}
u, err = user.LookupId(uidStr)