util

package
v0.0.0-...-5a6dc87 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArchAlias

func ArchAlias(arch string) string

ArchAlias returns the alias of cpu's architecture. amd64: x86_64 arm64: aarch64

func Bcrypt

func Bcrypt(password string) (string, error)

func ChangeDir

func ChangeDir(path string) error

func CopyDirectory

func CopyDirectory(src, dst string) error

func CopyDirectoryIfExists

func CopyDirectoryIfExists(src, dstDir string) error

func CopyFile

func CopyFile(src, dst string) error

func CopyFileToDir

func CopyFileToDir(src, dir string) error

func CountDirFiles

func CountDirFiles(dirName string) int

func CreateDir

func CreateDir(path string) error

func Exec

func Exec(ctx context.Context, name string, printOutput bool, printLine bool) (stdout string, code int, err error)

func ExecWithContext

func ExecWithContext(ctx context.Context, name string, printOutput bool, printLine bool) (stdout string, code int, err error)

func FileMD5

func FileMD5(path string) (string, error)

FileMD5 count file md5

func FormatBytes

func FormatBytes(bytes int64) string

func FormatSed

func FormatSed(darwin bool) string

func GetArgs

func GetArgs(argsMap map[string]string, args []string) ([]string, map[string]string)

func GetAvailableIP

func GetAvailableIP(ipAndMask string) []string

func GetAvailableIPRange

func GetAvailableIPRange(ipStart, ipEnd string) []string

func GetCommand

func GetCommand(c string) (string, error)

func GetCpu

func GetCpu() (string, int, int, error)

func GetDisk

func GetDisk() (uint64, uint64, error)

func GetFs

func GetFs() (string, string, error)

func GetHost

func GetHost() ([]string, error)

func GetLocalIP

func GetLocalIP() (net.IP, error)

GetLocalIP gets the local ip either by getting the "OS_LOCALIP" environment variable or by resolving the local hostname to IP address if the env is not set in both cases, the IP address is matched against the valid addresses of the local interfaces to check if it is an actually bindable address by valid it means the address is a non-loopback IPv4 address the explicitly specified env var takes precedence than the hostname if a valid IP is not found in both cases, a default IP is selected as a fallback

func GetMem

func GetMem() (uint64, uint64, error)

func GetNet

func GetNet()

func GetPs

func GetPs() ([]disk.PartitionStat, error)

func GetPublicIPFromAWSIMDS

func GetPublicIPFromAWSIMDS() (net.IP, error)

func GetPublicIPFromAliyunIMDS

func GetPublicIPFromAliyunIMDS() (net.IP, error)

func GetPublicIPFromTencentIMDS

func GetPublicIPFromTencentIMDS() (net.IP, error)

func GetPublicIPsFromOS

func GetPublicIPsFromOS() ([]net.IP, error)

GetPublicIPsFromOS gets a list of public ips by looking at the local network interfaces if any

func GetTokenFROMAWSIMDS

func GetTokenFROMAWSIMDS() (string, error)

func GetTokenFromAliyunIMDS

func GetTokenFromAliyunIMDS() (string, error)

func GetValidIPv4AddrsFromOS

func GetValidIPv4AddrsFromOS() ([]net.IP, error)

func Home

func Home() (string, error)

Home returns the home directory for the executing user.

func IPAddressToCIDR

func IPAddressToCIDR(ipAddress string) string

func IPMaskStringToCIDR

func IPMaskStringToCIDR(netmask string) string

func IsDir

func IsDir(path string) bool

func IsExecutable

func IsExecutable(path string) bool

func IsExist

func IsExist(path string) bool

func IsOnAWSEC2

func IsOnAWSEC2() bool

func IsOnAliyunECS

func IsOnAliyunECS() bool

func IsOnTencentCVM

func IsOnTencentCVM() bool

func IsValidIPv4Addr

func IsValidIPv4Addr(ip net.IP) bool

func LocalMd5Sum

func LocalMd5Sum(src string) string

func MkFileFullPathDir

func MkFileFullPathDir(fileName string) error

MkFileFullPathDir is used to file create the full path. eg. there is a file "./aa/bb/xxx.txt", and dir ./aa/bb is not exist, and will create the full path dir.

func Mkdir

func Mkdir(dirName string) error

func MoveDirectory

func MoveDirectory(src, dst string) error

func MoveFile

func MoveFile(src, dst string) error

func ParseIp

func ParseIp(ip string) []string

func RemoveDir

func RemoveDir(path string) error

func RemoveFile

func RemoveFile(path string) error

func RemoveHTTPPrefix

func RemoveHTTPPrefix(url string) string

func Render

func Render(tmpl *template.Template, variables any) (string, error)

Render text template with given `variables` Render-context

func ReplaceInFile

func ReplaceInFile(filepath, old, new string) error

func Round

func Round(val float64, precision int) float64

Round returns the result of rounding 'val' according to the specified 'precision' precision (the number of digits after the decimal point)。 and precision can be negative number or zero

func Sha256sum

func Sha256sum(path string) (string, error)

func ShortDur

func ShortDur(d time.Duration) string

func Tar

func Tar(src, dst, trimPrefix string) error

func Untar

func Untar(src, dst string) error

func WriteFile

func WriteFile(fileName string, content []byte, perm os.FileMode) error

Types

type Data

type Data map[string]interface{}

Jump to

Keyboard shortcuts

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