package sprigx import ( `os` `os/user` `strconv` `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) { 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 }