v1.16.4
ADDED: * math, time functions to tplx/sprigx FIXED: * logging not initializing properly on some BSDs
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user