Documentation ¶
Overview ¶
Package envite generated by go-bindata.// sources: ui/build/asset-manifest.json ui/build/favicon.ico ui/build/index.html ui/build/logo-large.svg ui/build/logo-small.svg ui/build/static/css/main.02ca4c04.css ui/build/static/js/27.3d9e48d0.chunk.js ui/build/static/js/main.71222bff.js ui/build/static/js/main.71222bff.js.LICENSE.txt
Index ¶
- Variables
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetFile() http.FileSystem
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func DescribeAvailableModes() string
- func Execute(server *Server, executionMode ExecutionMode) error
- func MustAsset(name string) []byte
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- type AnsiColor
- type Component
- type ComponentGraph
- type ComponentStatus
- type Environment
- func (b *Environment) Apply(ctx context.Context, enabledComponentIDs []string) error
- func (b *Environment) Cleanup(ctx context.Context) error
- func (b *Environment) Components() []Component
- func (b *Environment) Output() *Reader
- func (b *Environment) StartAll(ctx context.Context) error
- func (b *Environment) StartComponent(ctx context.Context, componentID string) error
- func (b *Environment) Status(ctx context.Context) (GetStatusResponse, error)
- func (b *Environment) StopAll(ctx context.Context) error
- func (b *Environment) StopComponent(ctx context.Context, componentID string) error
- type ErrInvalidComponentID
- type ErrInvalidExecutionMode
- type ExecutionMode
- type GetStatusResponse
- type GetStatusResponseComponent
- type LogLevel
- type Logger
- type Option
- type Reader
- type Server
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyEnvID indicates that an empty environment ID was provided. ErrEmptyEnvID = errors.New("environment ID cannot be empty") // ErrNilGraph indicates that a nil component graph was provided. ErrNilGraph = errors.New("environment component graph cannot be nil") )
Functions ¶
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetFile ¶
func AssetFile() http.FileSystem
AssetFile return a http.FileSystem instance that data backend by asset
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func DescribeAvailableModes ¶ added in v0.0.3
func DescribeAvailableModes() string
DescribeAvailableModes returns a string describing all available execution modes.
func Execute ¶
func Execute(server *Server, executionMode ExecutionMode) error
Execute performs the specified action based on the provided execution mode. It takes a Server instance and an ExecutionMode as parameters and executes the corresponding action. The available execution modes are ExecutionModeStart, ExecutionModeStop, and ExecutionModeDaemon.
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
Types ¶
type AnsiColor ¶
type AnsiColor struct{}
AnsiColor provides ANSI color codes for console output.
type Component ¶
type Component interface { // Type returns the type of the component. Type() string // AttachEnvironment associates the component with an environment and output writer. // It allows the component to interact with its environment and handle output properly. AttachEnvironment(ctx context.Context, env *Environment, writer *Writer) error // Prepare readies the component for operation. This may involve pre-start configuration or checks. Prepare(ctx context.Context) error // Start initiates the component's operation. // It should return any errors if encountered during startup. Start(ctx context.Context) error // Stop halts the component's operation. // It should return any errors if encountered during stop. Stop(ctx context.Context) error // Cleanup performs any necessary cleanup operations for the component, // such as removing temporary files or releasing external resources. Cleanup(ctx context.Context) error // Status reports the current operational status of the component. Status(ctx context.Context) (ComponentStatus, error) // Config returns the configuration of the component. // The exact return type can vary between component types. Config() any }
Component defines the interface for an environment component. It includes methods for lifecycle management, configuration, and status reporting.
type ComponentGraph ¶
type ComponentGraph struct {
// contains filtered or unexported fields
}
ComponentGraph represents a graph of components organized in layers. Each layer can contain one or more components that can depend on components from the previous layers. A layer is represented as a map, mapping from component ID to a component. Layer components are assumed to not depend on each other and can be operated on concurrently.
This structure is useful for initializing, starting, and stopping components in the correct order, ensuring that dependencies are correctly managed.
func NewComponentGraph ¶
func NewComponentGraph() *ComponentGraph
NewComponentGraph creates a new instance of ComponentGraph. It initializes an empty graph with no components and returns a pointer to it. This function is the starting point for building a graph of components by adding layers.
Example:
graph := NewComponentGraph(). .AddLayer({ "component-a": componentA, }) .AddLayer({ "component-b": componentB, "component-c": componentC, })
This example creates a new component graph and adds two layers to it.
func (*ComponentGraph) AddLayer ¶
func (c *ComponentGraph) AddLayer(components map[string]Component) *ComponentGraph
AddLayer adds a new layer of components to the ComponentGraph. Each call to AddLayer represents a new level in the graph, with the given components being added as a single layer. Components within the same layer are considered to have no dependencies on each other, but depend on components from all previous layers.
Parameters:
components map[string]Component: A mapping from component ID to a component implementation.
Example:
graph := NewComponentGraph(). .AddLayer({ "component-a": componentA, }) .AddLayer({ "component-b": componentB, "component-c": componentC, })
This example creates a new component graph and adds two layers to it.
type ComponentStatus ¶
type ComponentStatus string
ComponentStatus represents the operational status of a component within the environment.
const ( // ComponentStatusStopped indicates that the component is not currently running. ComponentStatusStopped ComponentStatus = "stopped" // ComponentStatusFailed indicates that the component has encountered an error and cannot continue operation. ComponentStatusFailed ComponentStatus = "failed" // ComponentStatusStarting indicates that the component is in the process of starting up but is not yet fully operational. ComponentStatusStarting ComponentStatus = "starting" // ComponentStatusRunning indicates that the component is currently operational and running as expected. ComponentStatusRunning ComponentStatus = "running" // ComponentStatusFinished indicates that the component has completed its operation successfully and has stopped running. ComponentStatusFinished ComponentStatus = "finished" )
type Environment ¶
type Environment struct { Logger Logger // contains filtered or unexported fields }
Environment represents a collection of components that can be managed together. Components within an environment can be started, stopped, and configured collectively or individually.
func NewEnvironment ¶
func NewEnvironment(id string, componentGraph *ComponentGraph, options ...Option) (*Environment, error)
NewEnvironment creates and initializes a new Environment with the specified id and component graph. It returns an error if the id is empty, the graph is nil, or if any components are misconfigured.
func (*Environment) Apply ¶
func (b *Environment) Apply(ctx context.Context, enabledComponentIDs []string) error
Apply applies the specified configuration to the environment, enabling only the components with IDs in enabledComponentIDs. It returns an error if applying the configuration fails.
func (*Environment) Cleanup ¶
func (b *Environment) Cleanup(ctx context.Context) error
Cleanup performs cleanup operations for all components within the environment. It returns an error if cleaning up any component fails.
func (*Environment) Components ¶
func (b *Environment) Components() []Component
Components returns a slice of all components within the environment.
func (*Environment) Output ¶
func (b *Environment) Output() *Reader
Output returns a reader for the environment's combined output from all components.
func (*Environment) StartAll ¶
func (b *Environment) StartAll(ctx context.Context) error
StartAll starts all components in the environment concurrently. It returns an error if starting any component fails.
func (*Environment) StartComponent ¶
func (b *Environment) StartComponent(ctx context.Context, componentID string) error
StartComponent starts a single component identified by componentID. It does nothing if the component is already running. Returns an error if the component fails to start.
func (*Environment) Status ¶
func (b *Environment) Status(ctx context.Context) (GetStatusResponse, error)
Status returns the current status of all components within the environment.
func (*Environment) StopAll ¶
func (b *Environment) StopAll(ctx context.Context) error
StopAll stops all components in the environment in reverse order of their startup. It returns an error if stopping any component fails.
func (*Environment) StopComponent ¶
func (b *Environment) StopComponent(ctx context.Context, componentID string) error
StopComponent stops a single component identified by componentID. Returns an error if the component fails to stop.
type ErrInvalidComponentID ¶
type ErrInvalidComponentID struct {
// contains filtered or unexported fields
}
ErrInvalidComponentID represents an error when a component ID is invalid.
func (ErrInvalidComponentID) Error ¶
func (e ErrInvalidComponentID) Error() string
type ErrInvalidExecutionMode ¶
type ErrInvalidExecutionMode struct {
// contains filtered or unexported fields
}
ErrInvalidExecutionMode is an error type representing an invalid execution mode. It is returned when attempting to parse an unrecognized execution mode.
func (ErrInvalidExecutionMode) Error ¶
func (e ErrInvalidExecutionMode) Error() string
type ExecutionMode ¶
type ExecutionMode string
ExecutionMode represents different execution modes for ENVITE. It can be used to specify the behavior when executing ENVITE commands.
const ( // ExecutionModeStart indicates the start execution mode, which starts all components in the environment, // and then exits. ExecutionModeStart ExecutionMode = "start" // ExecutionModeStop indicates the stop execution mode, which stops all components in the environment, // performs cleanup, and then exits. ExecutionModeStop ExecutionMode = "stop" // ExecutionModeDaemon indicates the daemon execution mode, which starts ENVITE as a daemon and serving a web UI. ExecutionModeDaemon ExecutionMode = "daemon" )
func ParseExecutionMode ¶
func ParseExecutionMode(value string) (ExecutionMode, error)
ParseExecutionMode parses the provided string value into an ExecutionMode. It returns the parsed ExecutionMode or an error if the value is not a valid execution mode.
type GetStatusResponse ¶
type GetStatusResponse struct { ID string `json:"id"` Components [][]GetStatusResponseComponent `json:"components"` }
GetStatusResponse defines the structure of the response for a status request. It includes details such as component ID, type, status, additional information, and environment variables.
type GetStatusResponseComponent ¶
type GetStatusResponseComponent struct { ID string `json:"id"` Type string `json:"type"` Status ComponentStatus `json:"status"` Config map[string]any `json:"config"` }
GetStatusResponseComponent represents a single component's status within the environment. It provides detailed information about the component, including its ID, type, current status, additional information specific to the component type, and environment variables associated with it.
Fields: - ID: A unique identifier for the component. - Type: The type of the component, indicating its role or function within the environment. - Status: The current status of the component, such as running, stopped, etc. - Config: The component config.
type LogLevel ¶
type LogLevel uint8
LogLevel represents the severity level of a log message.
const ( // LogLevelTrace represents the trace log level. LogLevelTrace LogLevel = iota // LogLevelDebug represents the debug log level. LogLevelDebug // LogLevelInfo represents the info log level. LogLevelInfo // LogLevelError represents the error log level. LogLevelError // LogLevelFatal represents the fatal log level. LogLevelFatal )
type Option ¶
type Option func(*Environment)
Option is a function type for configuring the Environment during initialization.
func WithLogger ¶
WithLogger is an Option function that sets the logger for the Environment.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader represents a reader for log messages.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an HTTP server, serving UI and API requests to manage the Environment when running in ExecutionModeDaemon.
func NewServer ¶
func NewServer(port string, env *Environment) *Server
NewServer creates a new Server instance for the given Environment.
type Writer ¶
type Writer struct { Color AnsiColor // contains filtered or unexported fields }
Writer represents a writer for log messages. Example:
writer.WriteString(writer.Color.Red("warning!"))
this writes a red messages to the console with the text "warning!"
func (*Writer) WriteString ¶
WriteString writes a log message with the current timestamp.
func (*Writer) WriteStringWithTime ¶
WriteStringWithTime writes a log message with a specified timestamp.