Documentation ¶
Index ¶
- Constants
- func CompareAddr(addr1, addr2 string) (int, error)
- func CompareIP(ip1, ip2 string) (int, error)
- func ExecuteCommand(command string) (output string, err error)
- func ExecuteCommandAndWait(command string) (output string, err error)
- func ExecuteCommandNoWait(command string) (output string, err error)
- func FindMountPoint(path string) (string, error)
- func GetDefaultIP() (string, error)
- func GetFileNameDest(fileNameSource, dirDest string) string
- func GetMinAddr(addrs []string) (string, error)
- func GetPathDirMapLocal(dirName, rootPath string) (map[string]string, error)
- func GetPidFromPidFile(pidFile string) (int, error)
- func HandleSignals(pidFile string, stopFuncs ...func() error)
- func IsDir(path string) (isDir bool, err error)
- func IsEmptyDir(dirName string) (isEmpty bool, err error)
- func IsRunningWithPid(pid int) (bool, error)
- func IsRunningWithPidFile(pidFile string) (bool, error)
- func IsValidIP(ip string) bool
- func KillServer(pid int, opts ...string) (err error)
- func MatchMountPoint(path string, mountPoints []string) (string, error)
- func PathExists(path string) (bool, error)
- func Readdir(dirName string) (fileInfoList []os.FileInfo, err error)
- func RemovePidFile(pidFile string) error
- func SavePid(pid int, pidFile string, fileMode os.FileMode) error
- func SendSignal(pid int, sig syscall.Signal, opts ...string) (err error)
- func ShutdownServer(pid int, opts ...string) (err error)
- func SortAddrs(addrs []string) error
- func SyscallMode(fileMode os.FileMode) (fileModeSys uint32)
- func TailN(fileName string, n int) (lines []string, err error)
- type SSHConfig
- type SSHConn
- func (conn *SSHConn) Cat(path string) (string, error)
- func (conn *SSHConn) Chmod(path string, mode string) error
- func (conn *SSHConn) Chown(path, user, group string) error
- func (conn *SSHConn) Close() error
- func (conn *SSHConn) Copy(src, dest string) error
- func (conn *SSHConn) CopyDirFromRemote(dirNameSource, dirNameDest string, tmpDir ...string) error
- func (conn *SSHConn) CopyDirToRemote(dirNameSource, dirNameDest string, tmpDir ...string) error
- func (conn *SSHConn) CopyFile(fileSource io.Reader, fileDest io.Writer, bufferSize int) error
- func (conn *SSHConn) CopyFromRemote(pathSource, pathDest string, tmpDir ...string) (err error)
- func (conn *SSHConn) CopySingleFileFromRemote(fileNameSource string, fileNameDest string, tmpDir ...string) error
- func (conn *SSHConn) CopySingleFileToRemote(fileNameSource string, fileNameDest string, tmpDir ...string) error
- func (conn *SSHConn) CopyToRemote(pathSource, pathDest string, tmpDir ...string) (err error)
- func (conn *SSHConn) ExecuteCommand(cmd string) (string, error)
- func (conn *SSHConn) ExecuteCommandWithoutOutput(cmd string) error
- func (conn *SSHConn) GetHostName() (string, error)
- func (conn *SSHConn) GetPathDirMapRemote(dirName, rootPath string) (map[string]string, error)
- func (conn *SSHConn) IsDir(path string) (bool, error)
- func (conn *SSHConn) IsEmptyDir(dirName string) (bool, error)
- func (conn *SSHConn) ListPath(path string) ([]string, error)
- func (conn *SSHConn) MkdirAll(path string) error
- func (conn *SSHConn) Move(src, dest string) error
- func (conn *SSHConn) PathExists(path string) (bool, error)
- func (conn *SSHConn) ReadDir(dirName string) ([]os.FileInfo, error)
- func (conn *SSHConn) RemoveAll(path string) error
- func (conn *SSHConn) SetUseSudo(useSudo bool)
- func (conn *SSHConn) Touch(path string) error
Constants ¶
const ( DefaultEstimateLineSize = 1024 MinStartPosition = 0 )
const ( DefaultSplitStr = constant.CRLFString DefaultSuccessReturnValue = constant.ZeroInt DefaultFailedReturnValue = constant.OneInt DefaultSSHTimeout = 10 * time.Second DefaultSSHPortNum = 22 DefaultSSHUserName = "root" DefaultSSHUserPass = "root" DefaultByteBufferSize = 1024 * 1024 // 1MB )
Variables ¶
This section is empty.
Functions ¶
func CompareAddr ¶ added in v0.3.17
CompareAddr compares two addresses, if addr1 is equal to addr2, it returns 0 if addr1 is less than addr2, it returns -1 if addr1 is greater than addr2, it returns 1
func CompareIP ¶ added in v0.3.17
CompareIP compares two ip addresses, if ip1 is equal to ip2, it returns 0 if ip1 is less than ip2, it returns -1 if ip1 is greater than ip2, it returns 1
func ExecuteCommand ¶ added in v0.1.4
ExecuteCommand is an alias of ExecuteCommandAndWait
func ExecuteCommandAndWait ¶ added in v0.1.20
ExecuteCommandAndWait executes shell command and wait for it to complete
func ExecuteCommandNoWait ¶ added in v0.1.20
ExecuteCommandNoWait executes shell command and does not wait for it to complete
func FindMountPoint ¶ added in v0.3.10
FindMountPoint returns the mount point of the given path, note that this function only works on unix-like system
func GetDefaultIP ¶
GetDefaultIP gets the default non-local ip, if there are more than one ips, it will return the first one
func GetFileNameDest ¶ added in v0.1.4
GetFileNameDest returns the destination file name
func GetMinAddr ¶ added in v0.3.17
GetMinAddr gets the minimum address from the addr list
func GetPathDirMapLocal ¶ added in v0.1.5
GetPathDirMapLocal reads all subdirectories and files of given directory and calculate the relative path of rootPath, then map the absolute path of subdirectory names and file names as keys, relative paths as values to fileDirMap
func GetPidFromPidFile ¶ added in v0.1.17
GetPidFromPidFile reads pid file and returns pid
func HandleSignals ¶ added in v0.3.17
HandleSignals handles operating system signals
func IsEmptyDir ¶ added in v0.1.4
IsEmptyDir returns if given directory is empty or not
func IsRunningWithPid ¶ added in v0.1.15
IsRunningWithPid returns if given pid is running
func IsRunningWithPidFile ¶ added in v0.1.15
IsRunningWithPidFile returns if process of which pid was saved in given pid file is running
func KillServer ¶ added in v0.1.18
KillServer kills server with given pid, it acts like shell command "kill -9", it will also remove pid file if pid file path is specified as opts
func MatchMountPoint ¶ added in v0.3.11
MatchMountPoint matches mount point of given path in the mount point slice, if nothing matched, it returns "/" as default mount point
func PathExists ¶ added in v0.1.5
PathExists returns if given path exists
func Readdir ¶ added in v0.1.4
Readdir returns subdirectories and files of given directory on the remote host, it returns a slice of os.FileInfo
func RemovePidFile ¶ added in v0.1.19
func SendSignal ¶ added in v0.2.19
SendSignal sends signal to given pid, it will also remove pid file if pid file path is specified as opts
func ShutdownServer ¶ added in v0.2.19
ShutdownServer kills server with given pid, it acts like shell command "kill -15", it will also remove pid file if pid file path is specified as opts
func SyscallMode ¶ added in v0.1.4
SyscallMode returns file mode which could be used at syscall
Types ¶
type SSHConfig ¶ added in v0.3.17
type SSHConfig struct { HostIp string PortNum int UserName string UserPass string // contains filtered or unexported fields }
func NewSSHConfig ¶ added in v0.3.17
func NewSSHConfig(hostIP string, portNum int, userName string, userPass string, useSudo bool) *SSHConfig
NewSSHConfig returns a new *SSHConfig
func NewSSHConfigWithDefault ¶ added in v0.3.17
NewSSHConfigWithDefault returns a new *SSHConfig with default values
func (*SSHConfig) SetUseSudo ¶ added in v0.3.17
SetUseSudo sets useSudo
type SSHConn ¶ added in v0.3.17
func NewSSHConn ¶ added in v0.3.17
func NewSSHConn(hostIP string, portNum int, userName, userPass string, useSudo bool) (*SSHConn, error)
NewSSHConn returns a new *SSHConn
func (*SSHConn) Cat ¶ added in v0.3.17
Cat returns the content of the given file on the remote host, it will act like shell command "cat $path"
func (*SSHConn) Chmod ¶ added in v0.3.17
Chmod changes the mode of the given path on the remote host, it will act like shell command "chmod -R $mode $path"
func (*SSHConn) Chown ¶ added in v0.3.17
Chown changes the owner and group of the given path on the remote host, it will act like shell command "chown -R $user:$group $path"
func (*SSHConn) Copy ¶ added in v0.3.17
Copy copies a file or directory on the remote host, it will act like shell command "copy -r $src $dest"
func (*SSHConn) CopyDirFromRemote ¶ added in v0.3.17
CopyDirFromRemote copies a directory with all subdirectories and files from remote to local
func (*SSHConn) CopyDirToRemote ¶ added in v0.3.17
CopyDirToRemote copies a directory with all subdirectories and files from local to remote
func (*SSHConn) CopyFile ¶ added in v0.3.17
CopyFile copy file content from source to destination, it doesn't care about which one is local or remote
func (*SSHConn) CopyFromRemote ¶ added in v0.3.17
CopyFromRemote copies no matter a directory or a file from remote to local
func (*SSHConn) CopySingleFileFromRemote ¶ added in v0.3.17
func (conn *SSHConn) CopySingleFileFromRemote(fileNameSource string, fileNameDest string, tmpDir ...string) error
CopySingleFileFromRemote copies one single file from remote to local. if tmpDir is not empty and is different with the parent directory of fileNameSource, it will copy the file to tmpDir on the remote host first, then transfer it to the local host, after that, it will remove the temporary file on the remote host automatically. it is your responsibility to assure that tmpDir exists and is a directory, the connection should have enough privilege to the tmpDir and the tmpDir has enough space to hold the file temporarily, note that only the first tmpDir will be used.
func (*SSHConn) CopySingleFileToRemote ¶ added in v0.3.17
func (conn *SSHConn) CopySingleFileToRemote(fileNameSource string, fileNameDest string, tmpDir ...string) error
CopySingleFileToRemote copies one single file from local to remote if tmpDir is not empty and is different with the parent directory of fileNameDest, it will transfer the file to tmpDir on the remote host first, then copy it to fileNameDest, after that, it will remove the temporary file on the remote host automatically. it is your responsibility to assure that tmpDir exists and is a directory, the connection should have enough privilege to the tmpDir and the tmpDir has enough space to hold the file temporarily, note that only the first tmpDir will be used.
func (*SSHConn) CopyToRemote ¶ added in v0.3.17
CopyToRemote copies no matter a directory or a file from local to remote
func (*SSHConn) ExecuteCommand ¶ added in v0.3.17
ExecuteCommand executes shell command on the remote host
func (*SSHConn) ExecuteCommandWithoutOutput ¶ added in v0.3.17
ExecuteCommandWithoutOutput executes a command without output
func (*SSHConn) GetHostName ¶ added in v0.3.17
GetHostName returns hostname of remote host
func (*SSHConn) GetPathDirMapRemote ¶ added in v0.3.17
GetPathDirMapRemote reads all subdirectories and files of given directory on the remote host and calculate the relative path of rootPath, then map the absolute path of subdirectory names and file names as keys, relative paths as values to fileDirMap
func (*SSHConn) IsDir ¶ added in v0.3.17
IsDir returns if given path on the remote host is a directory or not
func (*SSHConn) IsEmptyDir ¶ added in v0.3.17
IsEmptyDir returns if given directory is empty or not on the remote host
func (*SSHConn) ListPath ¶ added in v0.3.17
ListPath returns subdirectories and files of given path on the remote host, it returns a slice of sub paths
func (*SSHConn) MkdirAll ¶ added in v0.3.17
MkdirAll creates a directory named path, along with any necessary parents, on the remote host, it will act like shell command "mkdir -p $path"
func (*SSHConn) Move ¶ added in v0.3.17
Move moves a file or directory on the remote host, it will act like shell command "mv $src $dest"
func (*SSHConn) PathExists ¶ added in v0.3.17
PathExists returns if given path exists
func (*SSHConn) ReadDir ¶ added in v0.3.17
ReadDir returns subdirectories and files of given directory on the remote host, it returns a slice of os.FileInfo
func (*SSHConn) RemoveAll ¶ added in v0.3.17
RemoveAll removes given path on the remote host, it will act like shell command "rm -rf $path",
func (*SSHConn) SetUseSudo ¶ added in v0.3.17
SetUseSudo sets if use sudo or not