cmd

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 17 Imported by: 1

README

cmd

自用库

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fields added in v0.4.0

func Fields(src string) (out []string)

func Rotate added in v0.3.0

func Rotate(options LoggerOptions) io.WriteCloser

func Terminate added in v0.2.0

func Terminate(pid int, done <-chan struct{})

func WrapClose added in v0.3.0

func WrapClose(closers ...io.Closer) func()

Types

type Cmd

type Cmd struct {
	// contains filtered or unexported fields
}

func CommandLine added in v0.2.0

func CommandLine(commandLine string) *Cmd

解析单行命令

func New

func New(name string, args ...string) *Cmd

func Shell

func Shell(command string) *Cmd

执行脚本,在windows使用`cmd /c`, unix使用`bash/sh -c`(优先bash)

func (*Cmd) LineRead added in v0.4.0

func (c *Cmd) LineRead(lineRd func(flag, line string), transformers ...func(io.Reader) io.Reader) *Cmd

func (*Cmd) Logger added in v0.4.0

func (c *Cmd) Logger(options LoggerOptions) *Cmd

func (*Cmd) LoggerWriter added in v0.4.0

func (c *Cmd) LoggerWriter(w io.WriteCloser) *Cmd

func (*Cmd) PidFile added in v0.2.0

func (c *Cmd) PidFile(pidfile string) *Cmd

func (*Cmd) PostStart added in v0.3.0

func (c *Cmd) PostStart(task func(c *Cmd), parallel ...bool) *Cmd

func (*Cmd) PreExit added in v0.3.0

func (c *Cmd) PreExit(task func(c *Cmd), parallel ...bool) *Cmd

func (*Cmd) Run added in v0.3.0

func (c *Cmd) Run() (state *StartState)

func (*Cmd) RunWithContext added in v0.3.0

func (c *Cmd) RunWithContext(ctx context.Context) (state *StartState)

启动进程

func (*Cmd) Standard added in v0.4.0

func (c *Cmd) Standard() *Cmd

func (*Cmd) Stderr

func (c *Cmd) Stderr(w io.WriteCloser) *Cmd

func (*Cmd) Stdout

func (c *Cmd) Stdout(w io.WriteCloser) *Cmd

func (*Cmd) String

func (c *Cmd) String() string

进程描述

func (*Cmd) With

func (c *Cmd) With(options ...Option) *Cmd

add options

type FOption

type FOption func(cmd *exec.Cmd)

func (FOption) Apply

func (f FOption) Apply(cmd *exec.Cmd) error

type FOptionEx added in v0.3.0

type FOptionEx func(cmd *exec.Cmd) error

func (FOptionEx) Apply added in v0.3.0

func (f FOptionEx) Apply(cmd *exec.Cmd) error

type FileSize added in v0.3.0

type FileSize float64

func ParseSize added in v0.3.0

func ParseSize(s string) (FileSize, error)

mib, mb

func (FileSize) MarshalJSON added in v0.3.0

func (s FileSize) MarshalJSON() ([]byte, error)

func (FileSize) MarshalYAML added in v0.3.0

func (s FileSize) MarshalYAML() (any, error)

func (*FileSize) SetString added in v0.3.0

func (s *FileSize) SetString(in string) error

func (FileSize) String added in v0.3.0

func (s FileSize) String() string

func (FileSize) ToB added in v0.3.0

func (s FileSize) ToB() string

func (FileSize) ToIB added in v0.3.0

func (s FileSize) ToIB() string

func (*FileSize) UnmarshalJSON added in v0.3.0

func (s *FileSize) UnmarshalJSON(data []byte) error

func (*FileSize) UnmarshalYAML added in v0.3.0

func (s *FileSize) UnmarshalYAML(unmarshal func(any) error) error

type LoggerOptions added in v0.4.0

type LoggerOptions struct {
	Std     bool     `json:"std"`
	Path    string   `json:"path"`
	MaxSize FileSize `json:"max_size" yaml:"max_size"` //默认1M,最大100M
	Keep    int      `json:"keep"`                     //0, 不保留, -1, 保留所有
}

type Option

type Option interface{ Apply(cmd *exec.Cmd) error }

func Envs added in v0.3.0

func Envs(envs []string) Option

func User

func User(uid, pid uint32) Option

func WorkDir added in v0.3.0

func WorkDir(workDir string) Option

type Options

type Options []Option

func (Options) Apply

func (options Options) Apply(cmd *exec.Cmd)

type Pid added in v0.3.0

type Pid string

func (Pid) DelPid added in v0.3.0

func (f Pid) DelPid()

func (Pid) ReadPid added in v0.3.0

func (f Pid) ReadPid() (pid int)

func (*Pid) SetPid added in v0.3.0

func (f *Pid) SetPid(path string)

func (Pid) WritePid added in v0.3.0

func (f Pid) WritePid(pid int) Pid

type Runner added in v0.3.0

type Runner struct {
	// contains filtered or unexported fields
}

顺序执行

func (*Runner) Append added in v0.3.0

func (p *Runner) Append(task func(), parallel ...bool)

func (*Runner) Parallel added in v0.3.0

func (p *Runner) Parallel(run ...func())

func (*Runner) Run added in v0.3.0

func (p *Runner) Run()

type StartState added in v0.2.0

type StartState struct {
	PID    int
	Err    error
	Status Status
	// contains filtered or unexported fields
}

func (*StartState) Cancel added in v0.2.0

func (s *StartState) Cancel()

func (*StartState) Done added in v0.2.0

func (s *StartState) Done() <-chan struct{}

func (*StartState) Wait added in v0.2.0

func (s *StartState) Wait() error

type Status

type Status string
const (
	StatusStarting Status = "starting"
	StatusStarted  Status = "started"
	StatusStopping Status = "stopping"
	StatusStopped  Status = "stopped"
)

type Task added in v0.3.0

type Task struct {
	Parallel bool
	Run      func()
}

Directories

Path Synopsis
example
svcgo Module

Jump to

Keyboard shortcuts

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