backend

package
v0.0.0-...-4723b29 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewCmdOptions = func(options CmdOptions, name string, args ...string) Commander {
	cmdOptions := cmd.Options{
		Buffered:  options.Buffered,
		Streaming: options.Streaming,
	}
	return &CmdWrapper{Cmd: cmd.NewCmdOptions(cmdOptions, name, args...)}
}

NewCmdOptions creates a new command with specific options

Functions

func CommonRequest

func CommonRequest(backendName string, proc Commander, logger *slog.Logger, url string, payload any,
	method string, body io.Reader, contentType string, timeout int32, errorMsg string,
) error

CommonRequest is a generic function to make HTTP requests to the backend

func GetList

func GetList() []string

GetList returns list of registered backends

func HaveBackend

func HaveBackend(name string) bool

HaveBackend checks if backend is registered

func Register

func Register(name string, b Backend)

Register registers backend

Types

type Backend

type Backend interface {
	Configure(*slog.Logger, policies.PolicyRepo, map[string]any, config.BackendCommons) error
	Version() (string, error)
	Start(ctx context.Context, cancelFunc context.CancelFunc) error
	Stop(ctx context.Context) error
	FullReset(ctx context.Context) error

	GetStartTime() time.Time
	GetCapabilities() (map[string]any, error)
	GetRunningStatus() (RunningStatus, string, error)
	GetInitialState() RunningStatus

	ApplyPolicy(data policies.PolicyData, updatePolicy bool) error
	RemovePolicy(data policies.PolicyData) error
}

Backend is the interface that all backends must implement

func GetBackend

func GetBackend(name string) Backend

GetBackend returns a registered backend

type CmdOptions

type CmdOptions struct {
	Buffered  bool // Whether to buffer the output
	Streaming bool // Whether to stream the output
}

CmdOptions holds the options for command execution

type CmdStatus

type CmdStatus struct {
	PID      int   // Process ID of command
	Complete bool  // Whether the command has completed
	Exit     int   // Exit code of the command
	Error    error // Go error
	StopTs   int64 // Timestamp when the command was stopped
}

CmdStatus holds the status of a command

func ConvertStatus

func ConvertStatus(status cmd.Status) CmdStatus

ConvertStatus converts cmd.Status to our Status

type CmdWrapper

type CmdWrapper struct {
	*cmd.Cmd
}

CmdWrapper wraps the cmd.Cmd struct to implement CmdInterface

func (*CmdWrapper) GetStderr

func (c *CmdWrapper) GetStderr() <-chan string

GetStderr returns the stderr channel

func (*CmdWrapper) GetStdout

func (c *CmdWrapper) GetStdout() <-chan string

GetStdout returns the stdout channel

func (*CmdWrapper) Start

func (c *CmdWrapper) Start() <-chan CmdStatus

Start starts the command and returns a channel for its status

func (*CmdWrapper) Status

func (c *CmdWrapper) Status() CmdStatus

Status returns the current command status

func (*CmdWrapper) Stop

func (c *CmdWrapper) Stop() error

Stop stops the running command

type Commander

type Commander interface {
	Start() <-chan CmdStatus
	Stop() error
	Status() CmdStatus

	// For accessing output channels
	GetStdout() <-chan string
	GetStderr() <-chan string
}

Commander abstracts the functionality from go-cmd/cmd package

type RunningStatus

type RunningStatus int

RunningStatus is the status of the backend

const (
	Unknown RunningStatus = iota
	Running
	BackendError
	AgentError
	Offline
	Waiting
)

Running Status types

func GetRunningStatus

func GetRunningStatus(proc Commander) (RunningStatus, string, error)

GetRunningStatus checks the status of the backend process

func (RunningStatus) String

func (s RunningStatus) String() string

type State

type State struct {
	Status            RunningStatus
	RestartCount      int64
	LastError         string
	LastRestartTS     time.Time
	LastRestartReason string
}

State represents the state of the backend

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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