utils

package
v4.5.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Core @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

Index

Constants

View Source
const (
	Arch_x86_64 = "x86_64"
	Arch_ARM    = "arm"
	Arch_ARM64  = "arm64"
	Arch_RISC   = "risc"
	Arch_PPC    = "ppc"
)

Variables

View Source
var (
	ErrFailGetUser = Errs.New("Failed to get current user")
)
View Source
var (
	ErrFailedLoadConfig = Errs.New("Failed to load config")
)
View Source
var (
	ErrInvalidColor = Errs.New("Invalid color")
)
View Source
var (
	ErrInvalidSizeFormat = Errs.New("Invalid size format")
)
View Source
var (
	ErrInvalidUid = Errs.New("Invalid UID value")
)

Functions

func AnyToString

func AnyToString(val any) string

func Clamp

func Clamp[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](
	val T, min T, max T) T

func ColorHexPercent

func ColorHexPercent(color string, percent float64) string

func CreateDir

func CreateDir(path string) (bool, error)

func CreateUser

func CreateUser(name string, id int, home bool, system bool) error

func ExpandPath

func ExpandPath(path string) string

func FileModeToStr0xxx

func FileModeToStr0xxx(mode FileMode) string

func FindPathFileExt

func FindPathFileExt(paths []string, names []string, exts []string) string

func FormatByteSize

func FormatByteSize(size int64) (float64, string)

func FormatByteSizeString

func FormatByteSizeString(size int64) string

func FromBase36

func FromBase36(str string) (uint64, error)

func GetArch

func GetArch() string

func GetCWD

func GetCWD() string

func GetExecPath

func GetExecPath() string

func GetGroupID

func GetGroupID(name string) int

func GetHostName

func GetHostName() string

func GetNevra

func GetNevra(name string, version string, epoch uint16,
	release uint16, os string, arch string) string

name-[epoch_]version[-release][-os][-arch]

func GetOS

func GetOS() string

func GetRunPath

func GetRunPath() string

func GetUserID

func GetUserID(name string) int

func GroupExists

func GroupExists(name string) bool

func InPath

func InPath(name string) bool

func IsDir

func IsDir(path string) bool

func IsExisting

func IsExisting(path string) bool

func IsFile

func IsFile(file string) bool

func IsRootUser

func IsRootUser() (bool, error)

func IsSafeAlpha

func IsSafeAlpha(str string) bool

func IsSafeAlphaLower

func IsSafeAlphaLower(str string) bool

func IsSafeAlphaNum

func IsSafeAlphaNum(str string) bool

func IsSafeAlphaUpper

func IsSafeAlphaUpper(str string) bool

func IsSafeDomain

func IsSafeDomain(str string) bool

func IsSafeDomainPort

func IsSafeDomainPort(str string) bool

func IsSafeFilePath

func IsSafeFilePath(str string) bool

func IsSanSafe

func IsSanSafe(str string, pattern string) bool

func LoadConfig

func LoadConfig[T any](file string) (*T, error)

func LoadConfigR

func LoadConfigR[T any](file string) (*T, map[string]any, error)

func Max

func Max[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](
	vals ...T) T

func Min

func Min[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](
	vals ...T) T

func ParseBool

func ParseBool(value string) (bool, bool)

func ParseBoolDef

func ParseBoolDef(value string, defval bool) bool

func ParseByteSize

func ParseByteSize(size string) (int64, error)

func ParseHexColor

func ParseHexColor(color string) (int, int, int, error)

func ParseNevra

func ParseNevra(file string) (string, string)

func ParseOwnerID

func ParseOwnerID(own string) (int, int, error)

func RemoveIndex

func RemoveIndex[T any](array []T, index int) []T

remove index from array

func RunCommand

func RunCommand(timeout *Time.Duration, cmd string, args []string) error

func SafeFilePath

func SafeFilePath(str string) string

func SafeHTML

func SafeHTML(str string) string

func Sleep1ms

func Sleep1ms()

func Sleep1s

func Sleep1s()

func Sleep1sN

func Sleep1sN(n uint8)

func Sleep10ms

func Sleep10ms()

func Sleep10msN

func Sleep10msN(n uint8)

func Sleep50ms

func Sleep50ms()

func Sleep100ms

func Sleep100ms()

func Sleep100msN

func Sleep100msN(n uint8)

func SleepR

func SleepR()

default random sleep

func SleepRand

func SleepRand(lower int, upper int)

random sleep

func ToBase36

func ToBase36(val uint64) string

func UserExists

func UserExists(name string) bool

func ValidArch

func ValidArch(arch string) bool

Types

type FileMode

type FileMode FS.FileMode

func Str0xxxToFileMode

func Str0xxxToFileMode(str string) FileMode

func (FileMode) MarshalJSON

func (mod FileMode) MarshalJSON() ([]byte, error)

func (FileMode) MarshalYAML

func (mod FileMode) MarshalYAML() ([]byte, error)

func (*FileMode) UnmarshalJSON

func (mod *FileMode) UnmarshalJSON(data []byte) error

func (*FileMode) UnmarshalYAML

func (mod *FileMode) UnmarshalYAML(val *Yaml.Node) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL