Documentation ¶
Index ¶
- Constants
- func Alias(k, v string)
- func Cd(dir string) error
- func Chmod(name string, mode int64) error
- func Chown(name string, uid, gid int) error
- func Clear() error
- func Cp(opt CpOpt, src, dst string) error
- func CronParse(str string) (expr cronExpr, command string)
- func CrontabAdd(expr string, names ...string) error
- func CrontabDel(expr string, names ...string) error
- func Curl(opt CurlOpt, urls []string) ([]byte, error)
- func Echo(opt EchoOpt, str string) (string, error)
- func Environ(k string) string
- func Exec(opt ExecOpt, cmd string) (string, error)
- func Export(opt ExportOpt, k, v string) error
- func ExportL(k, v string) error
- func Find(opt FindOpt, path string) ([]string, error)
- func IPTablesListDarwin(str string) (rules []fireWareRuleDarwin, err error)
- func IPTablesListLinux(str string) (rules []fireWareRuleLinux, err error)
- func IPTablesListWindows(str string) (rules []firewareRuleWindows, err error)
- func IPTablesOp(opt IPTablesOpOpt) error
- func KillByName(name string) error
- func KillByPid(pid int32) error
- func MultiScript(name, s string) (string, error)
- func Mv(opt MvOpt, src, dst string) error
- func Nohup(cmds string) error
- func OnceScript(s string) (string, error)
- func PS(opt PSOpt) (info map[int32]*ProcessInfo, err error)
- func Rename(old, new string)
- func Rm(opt RmOpt, target string) error
- func SystemCtlCreate(name string, opt SCCreateOpt) error
- func SystemCtlDelete(server string) error
- func SystemCtlDisable(server string) error
- func SystemCtlIsEnable(name string) bool
- func SystemCtlRelaod(server string) error
- func SystemCtlStart(server string) error
- func SystemCtlStop(server string) error
- func Tar(src, dst string) error
- func Unalias(k string)
- func Unset(opt UnsetOpt, k, v string) error
- func UnsetL(k string) error
- func Untar(src, dst string) error
- func Unzip(src, dst string) error
- func Whereis(path string) (string, error)
- func Zip(src, dst string) error
- type ArgsBuilder
- type CpOpt
- type CronTask
- type CurlOpt
- type EchoOpt
- type ExecOpt
- type ExportOpt
- type FindOpt
- type FireWareRule
- type IPTablesListOpt
- type IPTablesOpOpt
- type IPTablesOperate
- type LsFileInfo
- type LsOpt
- type LsofInfo
- type MvOpt
- type PGrepResult
- type PSOpt
- type ProcessInfo
- type RmOpt
- type SCCreateOpt
- type SSHCenter
- type SSHClient
- type SSHOpt
- type SSHReader
- type SSHWriter
- type ServiceInfo
- type SystemCtlStatusOpt
- type Terminal
- type UnsetOpt
Examples ¶
Constants ¶
const ( A_LAST = 1 A_STEP = 2 A_ROUND = 4 A_NO = 8 A_INVALID = 16 A_ENUM = 32 )
const ( TermUndefined = iota TermPowershell TermCmd TermBash )
const (
UnsetExpandPosix = `#!/bin/bash
sed -i '/^export %s=%s/d' ~/.bashrc
. ~/.bashrc`
)
Variables ¶
This section is empty.
Functions ¶
func Cd ¶
Cd changes the current working directory to the named directory. If there is an error, it will be of type *PathError.
func Chmod ¶
Chmod changes the mode of the named file to mode. If the file is a symbolic link, it changes the mode of the link's target. If there is an error, it will be of type *PathError.
A different subset of the mode bits are used, depending on the operating system.
On Unix, the mode's permission bits, ModeSetuid, ModeSetgid, and ModeSticky are used.
On Windows, only the 0200 bit (owner writable) of mode is used; it controls whether the file's read-only attribute is set or cleared. The other bits are currently unused. For compatibility with Go 1.12 and earlier, use a non-zero mode. Use mode 0400 for a read-only file and 0600 for a readable+writable file.
On Plan 9, the mode's permission bits, ModeAppend, ModeExclusive, and ModeTemporary are used.
func Chown ¶
Chown changes the numeric uid and gid of the named file. If the file is a symbolic link, it changes the uid and gid of the link's target. A uid or gid of -1 means to not change that value. If there is an error, it will be of type *PathError.
On Windows or Plan 9, Chown always returns the syscall.EWINDOWS or EPLAN9 error, wrapped in *PathError.
func CrontabAdd ¶
func CrontabDel ¶
func Curl ¶
Curl is similar with curl, which is used to send Curl request according to opt and urls.
func Echo ¶
Echo prints str to the screen and returns str. Similar to GNU's echo, you can also print environment variables by $GOPATH
func IPTablesListDarwin ¶
func IPTablesListLinux ¶
func IPTablesListWindows ¶
func IPTablesOp ¶
func IPTablesOp(opt IPTablesOpOpt) error
func KillByName ¶
func MultiScript ¶
func OnceScript ¶
func SystemCtlCreate ¶
func SystemCtlCreate(name string, opt SCCreateOpt) error
func SystemCtlDelete ¶
func SystemCtlDisable ¶
func SystemCtlIsEnable ¶
func SystemCtlRelaod ¶
func SystemCtlStart ¶
func SystemCtlStop ¶
Types ¶
type ArgsBuilder ¶
type ArgsBuilder struct {
// contains filtered or unexported fields
}
func NewArgsBuilder ¶
func NewArgsBuilder(cmds ...string) *ArgsBuilder
func (*ArgsBuilder) Add ¶
func (builder *ArgsBuilder) Add(cmds ...string) *ArgsBuilder
func (*ArgsBuilder) AddInt ¶
func (builder *ArgsBuilder) AddInt(k string, i int) *ArgsBuilder
func (*ArgsBuilder) AddString ¶
func (builder *ArgsBuilder) AddString(k string, v string) *ArgsBuilder
func (*ArgsBuilder) Build ¶
func (builder *ArgsBuilder) Build() string
func (*ArgsBuilder) MustAddString ¶
func (builder *ArgsBuilder) MustAddString()
type CronTask ¶
func CrontabList ¶
type CurlOpt ¶
type CurlOpt struct { // Header contains the request header fields either received // by the server or to be sent by the client. Header map[string]string // Method specifies the HTTP method (GET, POST, PUT, etc.). Method string Data string Cookie *http.Cookie // Save will write body into specified file Save bool // Dir set root directory of file to be saved Dir string // FilenameHandle returns filename that will be saved according to url FilenameHandle func(string) string // Strict will exit at once when error occur Strict bool // Async will enable goroutines when it's true. // // maxRequestCount and wg to limit count of concurrent goroutines Async bool // contains filtered or unexported fields }
CurlOpt indicates configuration of HTTP request
type ExecOpt ¶
type ExecOpt struct { // Redirect set stdout, stderr, stdin stream Redirect bool Quiet bool Sandbox bool Terminal uint8 }
ExecOpt indicates configuration of exec
type FireWareRule ¶
type FireWareRule interface { Name() string Proto() string Src() string Dst() string Action() string }
func IPTablesList ¶
func IPTablesList(opt IPTablesListOpt) (rules []FireWareRule, err error)
type IPTablesListOpt ¶
type IPTablesOpOpt ¶
type IPTablesOpOpt struct { Chain string `json:"chain"` Name string `json:"name"` Protocol string `json:"protocol"` Destination string `json:"dest"` // linux: ACCEPT, DROP, REJECT, LOG, SNAT, DNAT, MASQUEREAD Action string `json:"action"` Legacy bool `json:"legacy"` Op IPTablesOperate `json:"op"` }
func (IPTablesOpOpt) ToLinux ¶
func (opt IPTablesOpOpt) ToLinux() string
func (IPTablesOpOpt) ToWindows ¶
func (opt IPTablesOpOpt) ToWindows() string
type LsFileInfo ¶
func Ls ¶
func Ls(opt LsOpt) ([]LsFileInfo, error)
type LsOpt ¶
type LsOpt struct { Dir string Callack func(path string, info fs.FileInfo) bool // contains filtered or unexported fields }
func (*LsOpt) SetRecurse ¶
func (opt *LsOpt) SetRecurse()
type LsofInfo ¶
type LsofInfo struct { Protocal string `json:"protocal"` Local string `json:"local"` Foreign string `json:"foregin"` State string `json:"state"` Pid int32 `json:"pid"` }
Example ¶
test.Batch(test.BatchOpt{ Path: "./testdata/lsof/linux", }).Range(func(data string) error { fmt.Println(lsofLinux(data)) return nil })
Output: [{tcp 0.0.0.0:22 0.0.0.0:* LISTEN 0} {tcp 127.0.0.1:631 0.0.0.0:* LISTEN 0} {tcp 127.0.0.53:53 0.0.0.0:* LISTEN 0} {tcp6 :::8080 :::* LISTEN 2717}]
type PGrepResult ¶
func PGrep ¶
func PGrep(name string) []PGrepResult
type ProcessInfo ¶
type SCCreateOpt ¶
type SCCreateOpt struct { Unit scCreateOptUnit `json:"unit"` Service scCreateOptService `json:"service"` Install scCreateOptInstall `json:"install"` }
func (*SCCreateOpt) String ¶
func (s *SCCreateOpt) String() string
type SSHCenter ¶
type SSHCenter struct {
// contains filtered or unexported fields
}
SSHCenter manages the SSHClient
type SSHClient ¶
SSHClient packs the SSH connection
func NewSSHClient ¶
type SSHOpt ¶
type SSHOpt struct { User string // password Pwd string IP string Port int // tcp, udp, etc. Network string Redirect bool }
SSHOpt indicates configuration of newSSHClient
type SSHReader ¶
type SSHReader struct {
// contains filtered or unexported fields
}
SSHReader implements io.Reader, which reads string stream by channel.
func NewSSHReader ¶
func NewSSHReader() *SSHReader
type SSHWriter ¶
type SSHWriter struct {
// contains filtered or unexported fields
}
SSHWriter implements io.Writer, which writes to a string stream by channel.
func NewSSHWriter ¶
func NewSSHWriter() *SSHWriter
type ServiceInfo ¶
func SystemCtlStatus ¶
func SystemCtlStatus(opt SystemCtlStatusOpt) (infos []ServiceInfo, err error)
type SystemCtlStatusOpt ¶
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
Terminal is a struct to abstract different termnial