rcom

package module
v0.0.0-...-69e0f3a Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2022 License: MIT Imports: 17 Imported by: 0

README

go-rcom

Executes remote CLI commands with input/output files

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GracefulShutdownTimeout = time.Minute
)

Functions

func ListenAndServe

func ListenAndServe(port uint16, gracefulShutdown bool, allowedCMDs ...string) error

func SetLogger

func SetLogger(l *golog.Logger)

SetLogger changes the logger used by the package. Passing nil disables logging. The default is github.com/domonda/golog/log.NewPackageLogger("rcom")

Types

type Client

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

Client is a base for building rcom base clients.

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient returns new client with attributes set by given opts.

func (*Client) Execute

func (c *Client) Execute(ctx context.Context, cmdArgs []string, files []fs.FileReader, resultFilePatterns ...string) (*Result, error)

Execute executes the service remotely with given arguments and returns a result. Method will panic if it is called when client allows execution of more then one commands, in that the ExecuteWithCommand should be used.

func (*Client) ExecuteWithCommand

func (c *Client) ExecuteWithCommand(ctx context.Context, cmd string, cmdArgs []string, files []fs.FileReader, resultFilePatterns ...string) (*Result, error)

Execute executes the services' cmd remotely with given arguments and returns a result.

type ClientOption

type ClientOption func(*Client)

ClientOption represents Client option.

func ClientWithCmds

func ClientWithCmds(cmds ...string) ClientOption

WithHost sets Client.cmds attribute.

func ClientWithHost

func ClientWithHost(host string) ClientOption

WithHost sets Client.host attribute.

func ClientWithPort

func ClientWithPort(port uint16) ClientOption

WithPort sets Client.port attribute.

func ClientWithTimeOut

func ClientWithTimeOut(timeout time.Duration) ClientOption

WithPort sets Client.timeout attribute.

type Command

type Command struct {
	Name               string
	Args               []string
	Stdin              []byte
	Files              map[string][]byte
	ResultFilePatterns []string
	// NonErrorExitCodes are non zero exit codes that should be returned
	// as Result.ExitCode instead of being considered an error
	NonErrorExitCodes map[int]bool
	// contains filtered or unexported fields
}

func (*Command) String

func (c *Command) String() string

func (*Command) Validate

func (c *Command) Validate() error

type Executer

type Executer interface {
	Execute(context.Context, *Command) (*Result, error)
}

func LocalExecuter

func LocalExecuter() Executer

type ExecuterFunc

type ExecuterFunc func(context.Context, *Command) (*Result, error)

func (ExecuterFunc) Execute

func (f ExecuterFunc) Execute(ctx context.Context, cmd *Command) (*Result, error)

type Result

type Result struct {
	CallID   uu.ID
	ExitCode int
	Output   string
	Stdout   string
	Stderr   string
	Files    map[string][]byte
	// contains filtered or unexported fields
}

func ExecuteLocally

func ExecuteLocally(ctx context.Context, c *Command) (result *Result, callID uu.ID, err error)

func ExecuteRemotely

func ExecuteRemotely(ctx context.Context, addr string, c *Command) (result *Result, err error)

func (*Result) WriteTo

func (r *Result) WriteTo(output fs.File) error

Directories

Path Synopsis
cmd
pkg
exec
Package exec is a replacement for os/exec and provides a Cmd struct that wraps os/exec.Cmd with additional builder design pattern methods and an option to kill sub processes.
Package exec is a replacement for os/exec and provides a Cmd struct that wraps os/exec.Cmd with additional builder design pattern methods and an option to kill sub processes.

Jump to

Keyboard shortcuts

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