utils

package
v0.0.0-...-7dd8fd7 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// CheckSymbol is the code for check symbol
	CheckSymbol = "\u2714 "
	// CrossSymbol is the code for check symbol
	CrossSymbol  = "\u2716 "
	ExclamSymbol = "\u0021 "
	ArrowSymbol  = "\u279c"
	DeleteSymbol = "\u2620"
	NoneSymbol   = "\u2605"
	// Message type
	Info     = "info"
	Err      = "error"
	Warn     = "warn"
	Inst     = "install"
	Uinst    = "uninstall"
	None     = "none"
	Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)

Variables

This section is empty.

Functions

func ArgumentsCheck

func ArgumentsCheck(argCount, min, max int) error

ArgumentsCheck check arguments count correctness

func CheckAndExit

func CheckAndExit(err error)

func Clear

func Clear()

clear screen

func CompressStr

func CompressStr(str string) string

compress string by regexp trim space or tab

func DeleteExtraSpace

func DeleteExtraSpace(s string) string
func Displaylogo()

func ErrorAssert

func ErrorAssert(err error, assert string) bool

错误断言

func Execute

func Execute(workDir, script string, args ...string) bool

Execute executes shell commands with arguments

func ExitN

func ExitN(messageType string, message string, code int)

func GetNodeIP

func GetNodeIP() string

GetNodeIP fetches node ip via command hostname. If it fails to get this, return empty string directly.

func GetOSName

func GetOSName() (string, error)

GetOSName gets data in /etc/os-release and gets OS name. For example, in a Ubuntu host, fetched data are like: root@i-8brpbc9t:~# cat /etc/os-release NAME="Ubuntu" VERSION="16.04.2 LTS (Xenial Xerus)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 16.04.2 LTS" VERSION_ID="16.04" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" VERSION_CODENAME=xenial UBUNTU_CODENAME=xenial

func GetUsername

func GetUsername() string

GetUsername return current username

func IsEmpty

func IsEmpty(path string) (bool, error)

check directory is or is not empty

func IsNumeric

func IsNumeric(val interface{}) bool

IsNumeric is_numeric() Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. In PHP hexadecimal (e.g. 0xf4c3b00c) is not supported, but IsNumeric is supported.

func IsSymLink(filepath string) (error, bool)

func MergeSlice

func MergeSlice(s1 []string, s2 []string) []string

func ParseAbsPath

func ParseAbsPath(filepath string, homeDir string) string

return relative file path if filepath is absolute

func ParseConnect

func ParseConnect(connectStr string) (string, string, string)

ParseConnect parse connect string, format is [user@]host[:port]

func ParseOriginalFilePath

func ParseOriginalFilePath(filepath string) string

return the original file path if file is a symbol link

func ParseRelPath

func ParseRelPath(filepath string, homeDir string) string

return absolute file path if filepath is relative

func PathExist

func PathExist(_path string) bool

check file is or is not exist

func PrintErr

func PrintErr(err error)

func PrintN

func PrintN(messageType string, message string)

func Query

func Query(values, keys []string, ignoreCase bool) bool

Query values contains keys

func Root

func Root() bool

func SortKeys

func SortKeys(m map[string]string) []string

SortKeys sort map keys

Types

type SystemVersion

type SystemVersion struct {
	Name string `json:"Name,omitempty"`

	// Arch type of underlying hardware
	Arch string `json:"Arch,omitempty"`

	// The time when this binary of daemon is built
	BuildTime string `json:"BuildTime,omitempty"`

	// Commit ID held by the latest commit operation
	GitCommit string `json:"GitCommit,omitempty"`

	// version of Go runtime
	GoVersion string `json:"GoVersion,omitempty"`

	// Operating system type of underlying system
	Os string `json:"Os,omitempty"`

	Version string `json:"Version,omitempty"`

	Banner string `json:"Banner,omitempty"`
	GitHub string `json:"GitHub,omitempty"`
}

func Version

func Version() (SystemVersion, error)

Jump to

Keyboard shortcuts

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