v1.16.3
ADDED: * Much more functions to tplx/sprigx
This commit is contained in:
@@ -1,13 +1,73 @@
|
||||
package sprigx
|
||||
|
||||
import (
|
||||
"os"
|
||||
`os`
|
||||
`os/user`
|
||||
`strconv`
|
||||
`strings`
|
||||
)
|
||||
|
||||
// osHostname returns os.Hostname()
|
||||
func osHostname() (out string, err error) {
|
||||
// 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) {
|
||||
|
||||
out, err = os.Hostname()
|
||||
var gidStr string
|
||||
|
||||
switch t := any(gid).(type) {
|
||||
case string:
|
||||
gidStr = t
|
||||
case int:
|
||||
gidStr = strconv.Itoa(t)
|
||||
}
|
||||
|
||||
g, err = user.LookupGroupId(gidStr)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
osFQDN (tries to) return the FQDN of this host.
|
||||
|
||||
Currently it just calls os.Hostname() but may be extended to "try harder" in the future.
|
||||
*/
|
||||
func osFQDN() (fqdn string, err error) {
|
||||
|
||||
fqdn, err = os.Hostname()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
osHost returns the system's "host shortname".
|
||||
|
||||
Currently it just calls os.Hostname() and takes the first
|
||||
"host label" (as RFCs refer to it), but it may be extended
|
||||
in the future.
|
||||
*/
|
||||
func osHost() (hostNm string, err error) {
|
||||
|
||||
hostNm, err = os.Hostname()
|
||||
|
||||
if hostNm == "" {
|
||||
return
|
||||
}
|
||||
hostNm = strings.Split(hostNm, ".")[0]
|
||||
|
||||
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) {
|
||||
|
||||
var uidStr string
|
||||
|
||||
switch t := any(uid).(type) {
|
||||
case string:
|
||||
uidStr = t
|
||||
case int:
|
||||
uidStr = strconv.Itoa(t)
|
||||
}
|
||||
|
||||
u, err = user.LookupId(uidStr)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user