Documentation ¶
Index ¶
- Constants
- Variables
- func AfterQuit(t time.Duration)
- func AsyncExec(cmd string) <-chan Result
- func ChildRunning(fn func(), exits ...func())
- func Close()
- func Closed() <-chan bool
- func CpuPercent() float64
- func CreateShellFile(pattern, content string) (tmpFile string, err error)
- func DefaultPingFunc(ip string) error
- func GetClientIP() ([]net.IP, error)
- func GetPublicIP() (net.IP, error)
- func GetPublicIPWithUrl(url string) (net.IP, error)
- func GetQuitCode() int32
- func GetQuitErr() error
- func GetResolveIP() (net.IP, error)
- func GetResolveIPList(filter func(ip net.IP) bool) ([]net.IP, error)
- func GetResolveIPV3(tt IPType, index int) (net.IP, error)
- func IPIsSelf(ip string) string
- func Info() string
- func IsLanIP(IP net.IP) bool
- func IsNormalQuit() bool
- func IsPublicIP(IP net.IP) bool
- func IsQuit() bool
- func MainRunning(fn func(), exits ...func())
- func PortUsed(port int) bool
- func PortUsedV2(ip string, port int) bool
- func PortsUsed(ports []int) []bool
- func Quit(code int)
- func QuitApp(code int32)
- func Recover(cleanups ...func())
- func SIToString(d *DiskPath, m *MemInfo, cpuPercent float64) string
- func SetQuitCode(code int32)
- func SetQuitErr(err error)
- func Stop(d time.Duration, stop chan bool)
- func StripArgs(args []string, arg string) []string
- func Wait(t time.Duration)
- type ArgOption
- type ArgOptionFunc
- type Child
- type Cmd
- type Config
- type CpuInfo
- type Ctrl
- func (c *Ctrl) Delay(delay, tick time.Duration, fun func(any) bool, param any, ...)
- func (c *Ctrl) DelayOnly(delay time.Duration, fun func(any) bool, param any, funcDefer func(any) bool, ...)
- func (c *Ctrl) RunAfter(timeout time.Duration, task Task) (any, error)
- func (c *Ctrl) RunWithContext(ctx context.Context, task Task) (any, error)
- func (c *Ctrl) Ticker(tick time.Duration, fun func(any) bool, param any, funcDefer func(any) bool, ...)
- type Daemon
- type DaemonConfig
- type DiskPath
- type Event
- type ExitSig
- type GetPublicIPFunc
- type GroupRun
- type IP
- func (p *IP) GetAllResolveIP() []net.IP
- func (p *IP) GetCurrentPublicIP() net.IP
- func (p *IP) GetCurrentResolveIP() net.IP
- func (p *IP) GetResolveIP() ([]net.IP, error)
- func (p *IP) PublicIPValid() bool
- func (p *IP) ResetCurrentPublicIP() net.IP
- func (p *IP) ResetCurrentResolveIP() net.IP
- func (p *IP) SelectResolveIP(pingFunc PingIPFunc) net.IP
- func (p *IP) SelfExternalIP(lan bool) string
- func (p *IP) SetCurrentResolveIP(ip net.IP)
- func (p *IP) SetPingIPFunc(fn PingIPFunc)
- func (p *IP) SetPublicIP(ip net.IP)
- func (p *IP) SetPublicIPFunc(fn GetPublicIPFunc)
- type IPType
- type MemInfo
- type Monitor
- type PingIPFunc
- type Process
- type ProcessCallback
- type RecoverFunc
- type Result
- type Running
- type RunningCheck
- type Shell
- type Status
- type Task
Constants ¶
const ( KStatusRunning = Status(1) KStatusClose = Status(2) KStatusExit = Status(3) )
const ( IptUnk = IPType(0) IptPub = IPType(1) IptPriA = IPType(2) IptPriB = IPType(3) IptPriC = IPType(4) )
const GB = 1024 * 1024 * 1024
const (
KLocalHost = "127.0.0.1"
)
const KMaxGroupCount = 3000
Variables ¶
var ( DefaultDaemonConfig = DaemonConfig{Config: Config{EnableEnv: true, EnableStd: false}} DefaultGroupRun *GroupRun = nil CmdNilErr = errors.New("cmd obj is nil") MaxCountErr = errors.New("max count") MaxErr = errors.New("max error") )
var ( TimeoutError = errors.New("operation timed out") ClosedError = errors.New("process closed") )
var ErrNormalQuit = errors.New("normal quit")
Functions ¶
func ChildRunning ¶ added in v1.8.0
func ChildRunning(fn func(), exits ...func())
func CpuPercent ¶ added in v1.4.9
func CpuPercent() float64
func CreateShellFile ¶ added in v1.20.37
CreateShellFile 创建临时的 shell 脚本文件 content 创建的脚本内容
func DefaultPingFunc ¶ added in v1.20.71
func GetClientIP ¶ added in v1.4.13
func GetPublicIP ¶ added in v0.5.39
func GetQuitCode ¶ added in v1.20.9
func GetQuitCode() int32
func GetQuitErr ¶ added in v1.20.9
func GetQuitErr() error
func GetResolveIP ¶ added in v0.5.39
func GetResolveIPList ¶ added in v1.20.71
func IsNormalQuit ¶ added in v1.20.9
func IsNormalQuit() bool
func IsPublicIP ¶
func MainRunning ¶ added in v1.8.0
func MainRunning(fn func(), exits ...func())
func PortUsedV2 ¶ added in v1.20.75
func SIToString ¶ added in v1.4.9
func SetQuitCode ¶ added in v1.20.9
func SetQuitCode(code int32)
func SetQuitErr ¶ added in v1.20.9
func SetQuitErr(err error)
Types ¶
type ArgOptionFunc ¶ added in v1.6.21
type ArgOptionFunc func(arg *ArgOption)
type Child ¶ added in v1.6.21
type Child struct { Data interface{} // contains filtered or unexported fields }
type Cmd ¶ added in v1.6.21
type Cmd struct { Cmd *exec.Cmd Err error Data interface{} // contains filtered or unexported fields }
type CpuInfo ¶ added in v1.0.16
type Ctrl ¶ added in v1.8.68
type Ctrl struct { }
func (*Ctrl) RunWithContext ¶ added in v1.8.68
type Daemon ¶ added in v1.6.21
type Daemon struct { }
func (*Daemon) Background ¶ added in v1.6.21
func (*Daemon) Background(id int, args []string, conf DaemonConfig, opts ...ArgOptionFunc) (*Cmd, error)
func (*Daemon) Group ¶ added in v1.6.21
func (*Daemon) Group(group int, args []string, cb ProcessCallback, config DaemonConfig, opts ...ArgOptionFunc)
Group 守护进程启动一个N[1,2000]子进程, 并循环监视
func (*Daemon) Run ¶ added in v1.6.21
func (d *Daemon) Run(groupId int, args []string, cb ProcessCallback, config DaemonConfig, opts ...ArgOptionFunc) int
Run 守护进程启动一个子进程, 并循环监视
type DaemonConfig ¶ added in v1.6.21
type DiskPath ¶ added in v1.0.16
type DiskPath struct { Path string `json:"path,omitempty"` Total uint64 `json:"total"` Free uint64 `json:"free"` Used uint64 `json:"used"` UsedPercent float64 `json:"usedPercent"` }
func DiskWithPath ¶ added in v1.8.36
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event represents a one-time event that may occur in the future.
func (*Event) Done ¶
func (e *Event) Done() <-chan struct{}
Done returns a channel that will be closed when Fire is called.
type GroupRun ¶ added in v1.6.21
type GroupRun struct {
// contains filtered or unexported fields
}
func (*GroupRun) Exec ¶ added in v1.6.21
func (g *GroupRun) Exec(cb ProcessCallback, config DaemonConfig, opts ...ArgOptionFunc)
type IP ¶ added in v1.20.71
type IP struct {
// contains filtered or unexported fields
}
func (*IP) GetAllResolveIP ¶ added in v1.20.76
func (*IP) GetCurrentPublicIP ¶ added in v1.20.73
func (*IP) GetCurrentResolveIP ¶ added in v1.20.71
func (*IP) PublicIPValid ¶ added in v1.20.71
func (*IP) ResetCurrentPublicIP ¶ added in v1.20.73
func (*IP) ResetCurrentResolveIP ¶ added in v1.20.71
func (*IP) SelectResolveIP ¶ added in v1.20.71
func (p *IP) SelectResolveIP(pingFunc PingIPFunc) net.IP
func (*IP) SelfExternalIP ¶ added in v1.20.71
SelfExternalIP 自己外部IP,可能是局域网IP,公网IP lan 局域网优先
func (*IP) SetCurrentResolveIP ¶ added in v1.20.71
func (*IP) SetPingIPFunc ¶ added in v1.20.71
func (p *IP) SetPingIPFunc(fn PingIPFunc)
func (*IP) SetPublicIP ¶ added in v1.20.71
func (*IP) SetPublicIPFunc ¶ added in v1.20.71
func (p *IP) SetPublicIPFunc(fn GetPublicIPFunc)
type MemInfo ¶ added in v1.0.0
type MemInfo struct { // Total amount of RAM on this system Total uint64 `json:"total"` // RAM available for programs to allocate // // This value is computed from the kernel specific values. Available uint64 `json:"available"` // RAM used by programs // // This value is computed from the kernel specific values. Used uint64 `json:"used"` // Percentage of RAM used by programs // // This value is computed from the kernel specific values. UsedPercent float64 `json:"usedPercent"` }
type Monitor ¶ added in v1.4.9
type PingIPFunc ¶ added in v1.20.71
func PingCheck ¶ added in v1.20.75
func PingCheck(port int) PingIPFunc
type Process ¶ added in v1.20.58
type Process interface { // Pid is the process ID for this process. Pid() int32 // PPid is the parent process ID for this process. PPid() int32 // Name name running this process. This is not a path to the Name() string Path() string }
Process is the generic interface that is implemented on every platform and provides common operations for processes.
func FindProcessByName ¶ added in v1.20.58
FindProcessByName looks up a single process by pid.
Process will be nil and error will be nil if a matching process is not found.
func FindProcessByPId ¶ added in v1.20.58
FindProcessByPId looks up a single process by pid.
Process will be nil and error will be nil if a matching process is not found.
func Processes ¶ added in v1.20.58
Processes returns all processes.
This of course will be a point-in-time snapshot of when this method was called. Some operating systems don't provide snapshot capability of the process table, in which case the process table returned might contain ephemeral entities that happened to be running when this was called.
type ProcessCallback ¶ added in v1.6.21
type RecoverFunc ¶ added in v1.8.0
type RecoverFunc func(r any)
var DefRecoverFunc RecoverFunc = func(r any) {
}
type Result ¶ added in v1.20.37
type Result struct { Command string Err error StartTime time.Time EndTime time.Time // contains filtered or unexported fields }
type Running ¶ added in v1.6.6
type Running struct {
// contains filtered or unexported fields
}
type RunningCheck ¶ added in v1.8.0
type RunningCheck struct {
// contains filtered or unexported fields
}
func (*RunningCheck) GoRunning ¶ added in v1.8.59
func (rc *RunningCheck) GoRunning(fn func(), exits ...func())
func (*RunningCheck) GoRunningV2 ¶ added in v1.8.59
func (rc *RunningCheck) GoRunningV2(running func(), fn func(), exits ...func())
func (*RunningCheck) IsRunning ¶ added in v1.8.0
func (rc *RunningCheck) IsRunning() bool
func (*RunningCheck) TryGoRunning
deprecated
added in
v1.8.0
func (rc *RunningCheck) TryGoRunning(fn func(), exits ...func())
Deprecated: this function simply calls [GoRunning].
type Shell ¶ added in v1.0.58
type Shell struct { }
func (*Shell) RunTimeout ¶ added in v1.20.37
RunTimeout 阻塞式超时同步执行