shell

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Hostname = shellapi.Hostname
	Version  = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Intermediate

type Intermediate struct {
	*connector.Connector
	ToDo
}

Intermediate extends and customizes the generic base connector.

func NewIntermediate

func NewIntermediate(impl ToDo) *Intermediate

NewIntermediate creates a new instance of the intermediate.

func (*Intermediate) MaxOutputBytes

func (svc *Intermediate) MaxOutputBytes() (value int)

MaxOutputBytes caps the number of bytes retained from each of stdout and stderr. When a stream exceeds this cap, the head and tail are kept and the middle is elided with a marker. The command is not killed; excess output is silently discarded so the child can run to completion.

func (*Intermediate) SetMaxOutputBytes

func (svc *Intermediate) SetMaxOutputBytes(value int) (err error)

SetMaxOutputBytes sets the value of the configuration property.

type Mock

type Mock struct {
	*Intermediate
	// contains filtered or unexported fields
}

Mock is a mockable version of the microservice, allowing functions, event sinks and web handlers to be mocked.

func NewMock

func NewMock() *Mock

NewMock creates a new mockable version of the microservice.

func (*Mock) Execute

func (svc *Mock) Execute(ctx context.Context, cmd string, workDir string, stdin string, envars map[string]string) (exitCode int, stdout string, stderr string, err error)

Execute executes the mock handler.

func (*Mock) MockExecute

func (svc *Mock) MockExecute(handler func(ctx context.Context, cmd string, workDir string, stdin string, envars map[string]string) (exitCode int, stdout string, stderr string, err error)) *Mock

MockExecute sets up a mock handler for Execute.

func (*Mock) OnShutdown

func (svc *Mock) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Mock) OnStartup

func (svc *Mock) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

type Service

type Service struct {
	*Intermediate // IMPORTANT: Do not remove

}

Service implements the shell.core microservice.

Shell enables running shell commands on a host machine. It executes commands in a subprocess and returns the exit code, standard output, and standard error.

func NewService

func NewService() *Service

NewService creates a new instance of the microservice.

func (*Service) Execute

func (svc *Service) Execute(ctx context.Context, cmd string, workDir string, stdin string, envars map[string]string) (exitCode int, stdout string, stderr string, err error)

Execute runs a shell command on the host and returns the exit code, standard output, and standard error.

Input:

  • cmd: the shell command to execute
  • workDir: optional working directory for the command
  • stdin: optional standard input to feed to the command
  • envars: optional environment variables to set for the command, as key-value pairs

Output:

  • exitCode: the exit code of the command
  • stdout: the standard output of the command
  • stderr: the standard error of the command

func (*Service) Init

func (svc *Service) Init(initializer func(svc *Service) (err error)) *Service

Init enables a single-statement pattern for initializing the microservice.

func (*Service) OnShutdown

func (svc *Service) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Service) OnStartup

func (svc *Service) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

type ToDo

type ToDo interface {
	OnStartup(ctx context.Context) (err error)
	OnShutdown(ctx context.Context) (err error)
	Execute(ctx context.Context, cmd string, workDir string, stdin string, envars map[string]string) (exitCode int, stdout string, stderr string, err error) // MARKER: Execute
}

ToDo is implemented by the service or mock. The intermediate delegates handling to this interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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