Documentation ¶
Index ¶
- Constants
- Variables
- func ArgumentsCheck(argCount, min, max int) error
- func CheckAndExit(err error)
- func CheckConnect(connect string) error
- func CheckErr(err error) bool
- func Clear()
- func CompressStr(str string) string
- func Converted2Rendered(r io.Reader, w io.Writer, prefix string)
- func DeleteExtraSpace(s string) string
- func ErrorAssert(err error, assert string) bool
- func Execute(workDir, script string, args ...string) bool
- func ExitN(messageType string, message string, code int)
- func GetColor() (string, color.Color)
- func GetNodeIP() string
- func GetOSName() (string, error)
- func GetUsername() string
- func Install(osName string, dir string) error
- func IsEmpty(path string) (bool, error)
- func IsNumeric(val interface{}) bool
- func IsSymLink(filepath string) (error, bool)
- func MergeSlice(s1 []string, s2 []string) []string
- func ParseAbsPath(filepath string, homeDir string) string
- func ParseConnect(connectStr string) (string, string, string)
- func ParseOriginalFilePath(filepath string) string
- func ParseRelPath(filepath string, homeDir string) string
- func PathExist(_path string) bool
- func PrintErr(err error)
- func PrintErrWithPrefix(prefix string, err error)
- func PrintN(messageType string, message string)
- func Query(values, keys []string, ignoreCase bool) bool
- func Render(tpl *template.Template, data interface{}) []byte
- func RenderedOutput(wr io.Writer, line ColorLine) error
- func RenderedTpl() *template.Template
- func Root() bool
- func SortKeys(m map[string]string) []string
- func Uninstall(osName string, dir string) error
- type ColorLine
- type SSHSession
- type SystemVersion
- type VersionInfo
Constants ¶
const ( ColorRed = "red" ColorGreen = "green" ColorYellow = "yellow" ColorBlue = "blue" ColorMagenta = "magenta" ColorCyan = "cyan" ColorWhite = "white" ColorGray = "gray" )
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 ¶
var ErrAbort = errors.New("")
ErrAbort is the error returned when confirm prompts are supplied "n"
var ErrEOF = errors.New("^D")
ErrEOF is the error returned from prompts when EOF is encountered.
var ErrInterrupt = errors.New("^C")
ErrInterrupt is the error returned from prompts when an interrupt (ctrl-c) is encountered.
Functions ¶
func ArgumentsCheck ¶
ArgumentsCheck check arguments count correctness
func CheckAndExit ¶
func CheckAndExit(err error)
func CheckConnect ¶
check connect string, format is [user@]host[:port]
func DeleteExtraSpace ¶
func GetNodeIP ¶
func GetNodeIP() string
GetNodeIP fetches node ip via command hostname. If it fails to get this, return empty string directly.
func GetOSName ¶
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 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 MergeSlice ¶
func ParseAbsPath ¶
ParseAbsPath return relative file path if filepath is absolute
func ParseConnect ¶
ParseConnect parse connect string, format is [user@]host[:port]
func ParseOriginalFilePath ¶
ParseOriginalFilePath return the original file path if file is a symbol link
func ParseRelPath ¶
ParseRelPath return absolute file path if filepath is relative
func PrintErrWithPrefix ¶
func RenderedTpl ¶
Types ¶
type SSHSession ¶
type SSHSession struct { Stdin io.Writer Stdout io.Reader Stderr io.Reader // contains filtered or unexported fields }
func NewSSHSessionWithRoot ¶
func NewSSHSessionWithRoot(session *ssh.Session, useSudo, noPasswordSudo bool, rootPassword, userPassword string) *SSHSession
New Session and auto switch root user
func NewSSHSessionWithRootAndCmdDelay ¶
func NewSSHSessionWithRootAndCmdDelay(session *ssh.Session, useSudo, noPasswordSudo bool, rootPassword, userPassword string, cmdDelay time.Duration) *SSHSession
New Session and auto switch root user(support custom switch cmd delay)
func (*SSHSession) TerminalWithKeepAlive ¶
func (s *SSHSession) TerminalWithKeepAlive(serverAliveInterval time.Duration) error
TerminalWithKeepAlive open a interactive terminal shell with keepalive
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"` }
func Version ¶
func Version() (SystemVersion, error)
type VersionInfo ¶
type VersionInfo struct { Kernel int // Version of the kernel (e.g. 4.1.2-generic -> 4) Major int // Major part of the kernel version (e.g. 4.1.2-generic -> 1) Minor int // Minor part of the kernel version (e.g. 4.1.2-generic -> 2) Flavor string // Flavor of the kernel version (e.g. 4.1.2-generic -> generic) }
VersionInfo holds information about the kernel.
func GetKernelVersion ¶
func GetKernelVersion() (*VersionInfo, error)
GetKernelVersion returns the kernel version info.
func (*VersionInfo) String ¶
func (k *VersionInfo) String() string
String returns the kernel version's string format.