host

package
v0.0.0-alpha9 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	// Path is the path of the command to run.
	//
	// This is the only field that must be set to a non-zero
	// value. If Path is relative, it is evaluated relative
	// to Dir.
	Path string

	// Args holds command line arguments, including the command as Args[0].
	// If the Args field is empty or nil, Run uses {Path}.
	Args []string

	// Env specifies the environment of the process.
	// Each entry is of the form "key=value".
	// If Env is nil, the new process uses LANG=en_US.UTF-8
	// If Env contains duplicate environment keys, only the last
	// value in the slice for each duplicate key is used.
	Env []string

	// Dir specifies the working directory of the command.
	// If Dir is the empty string, Run runs the command in /tmp
	Dir string

	// Stdin specifies the process's standard input.
	//
	// If Stdin is nil, the process reads from the null device (os.DevNull).
	//
	// If Stdin is an *os.File, the process's standard input is connected
	// directly to that file.
	//
	// Otherwise, during the execution of the command a separate
	// goroutine reads from Stdin and delivers that data to the command
	// over a pipe. In this case, Wait does not complete until the goroutine
	// stops copying, either because it has reached the end of Stdin
	// (EOF or a read error), or because writing to the pipe returned an error,
	// or because a nonzero WaitDelay was set and expired.
	Stdin io.Reader
}

Cmd represents a command to be run.

func (Cmd) String

func (c Cmd) String() string

type Host

type Host interface {
	// Chmod works similar to os.Chmod.
	Chmod(ctx context.Context, name string, mode os.FileMode) error

	// Chown works similar to os.Chown.
	Chown(ctx context.Context, name string, uid, gid int) error

	// Lookup works similar to os/user.Lookup
	Lookup(ctx context.Context, username string) (*user.User, error)

	// LookupGroup works similar to os/user.LookupGroup
	LookupGroup(ctx context.Context, name string) (*user.Group, error)

	// Lstat works similar to os.Lstat, but it always returns non-nil Sys().
	Lstat(ctx context.Context, name string) (os.FileInfo, error)

	// ReadFile works similar to os.ReadFile.
	ReadFile(ctx context.Context, name string) ([]byte, error)

	// Remove works similar to os.Remove.
	Remove(ctx context.Context, name string) error

	// Run starts the specified command and waits for it to complete.
	// Returns WaitStatus, stdout, stderr, error
	Run(ctx context.Context, cmd Cmd) (WaitStatus, string, string, error)

	// WriteFile works similar to os.WriteFile.
	WriteFile(ctx context.Context, name string, data []byte, perm os.FileMode) error

	// A string representation of the host which uniquely identifies it, eg, its FQDN.
	String() string
}

Host defines an interface for interacting with a host.

type Local

type Local struct{}

Local interacts with the local machine running the code.

func (Local) Chmod

func (l Local) Chmod(ctx context.Context, name string, mode os.FileMode) error

func (Local) Chown

func (l Local) Chown(ctx context.Context, name string, uid, gid int) error

func (Local) Lookup

func (l Local) Lookup(ctx context.Context, username string) (*user.User, error)

func (Local) LookupGroup

func (l Local) LookupGroup(ctx context.Context, name string) (*user.Group, error)

func (Local) Lstat

func (l Local) Lstat(ctx context.Context, name string) (os.FileInfo, error)

func (Local) ReadFile

func (l Local) ReadFile(ctx context.Context, name string) ([]byte, error)

func (Local) Remove

func (l Local) Remove(ctx context.Context, name string) error

func (Local) Run

func (l Local) Run(ctx context.Context, cmd Cmd) (WaitStatus, string, string, error)

func (Local) String

func (l Local) String() string

func (Local) WriteFile

func (l Local) WriteFile(ctx context.Context, name string, data []byte, perm os.FileMode) error

type Ssh

type Ssh struct {
	Hostname string
}

Ssh interacts with a remote machine connecting to it via SSH protocol.

func (Ssh) Chmod

func (s Ssh) Chmod(ctx context.Context, name string, mode os.FileMode) error

func (Ssh) Chown

func (s Ssh) Chown(ctx context.Context, name string, uid, gid int) error

func (Ssh) Lookup

func (s Ssh) Lookup(ctx context.Context, username string) (*user.User, error)

func (Ssh) LookupGroup

func (s Ssh) LookupGroup(ctx context.Context, name string) (*user.Group, error)

func (Ssh) Lstat

func (s Ssh) Lstat(ctx context.Context, name string) (os.FileInfo, error)

func (Ssh) ReadFile

func (s Ssh) ReadFile(ctx context.Context, name string) ([]byte, error)

func (Ssh) Remove

func (s Ssh) Remove(ctx context.Context, name string) error

func (Ssh) Run

func (s Ssh) Run(ctx context.Context, cmd Cmd) (WaitStatus, string, string, error)

func (Ssh) String

func (s Ssh) String() string

func (Ssh) WriteFile

func (s Ssh) WriteFile(ctx context.Context, name string, data []byte, perm os.FileMode) error

type WaitStatus

type WaitStatus struct {
	// ExitCode returns the exit code of the exited process, or -1 if the process hasn't exited or was terminated by a signal.
	ExitCode int
	// Exited reports whether the program has exited. On Unix systems this reports true if the program exited due to calling exit, but false if the program terminated due to a signal.
	Exited bool
	// Signal describes a process signal.
	Signal string
}

WaitStatus

func (*WaitStatus) String

func (ws *WaitStatus) String() string

func (*WaitStatus) Success

func (ws *WaitStatus) Success() bool

Success reports whether the program exited successfully, such as with exit status 0 on Unix.

Jump to

Keyboard shortcuts

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