Documentation ¶
Index ¶
- Constants
- func CreateLogger(c *cli.Context, opts *CLIOpts, conf config.Type, streamsMode bool) (logger log.Modular, err error)
- func DelayShutdown(ctx context.Context, duration time.Duration) error
- func EnvFileAndTemplateFlags(opts *CLIOpts, hidden bool) []cli.Flag
- func PreApplyEnvFilesAndTemplates(c *cli.Context, opts *CLIOpts) error
- func ReadConfig(c *cli.Context, cliOpts *CLIOpts, streamsMode bool) (mainPath string, inferred bool, conf *config.Reader)
- func RunFlags(opts *CLIOpts, hidden bool) []cli.Flag
- func RunManagerUntilStopped(c *cli.Context, opts *CLIOpts, conf config.Type, stopMgr *StoppableManager, ...) error
- func RunService(c *cli.Context, cliOpts *CLIOpts, streamsMode bool) error
- type CLIOpts
- type ErrExitCode
- type RootCommonFlags
- func (r *RootCommonFlags) GetChilled(c *cli.Context) bool
- func (r *RootCommonFlags) GetConfig(c *cli.Context) string
- func (r *RootCommonFlags) GetLogLevel(c *cli.Context) string
- func (r *RootCommonFlags) GetResources(c *cli.Context) []string
- func (r *RootCommonFlags) GetSet(c *cli.Context) []string
- func (r *RootCommonFlags) GetWatcher(c *cli.Context) bool
- type RunningStream
- type StoppableManager
- type StreamInitFunc
- type SwappableStopper
Constants ¶
const ( RootFlagConfig = "config" RootFlagLogLevel = "log.level" RootFlagSet = "set" RootFlagResources = "resources" RootFlagChilled = "chilled" RootFlagWatcher = "watcher" RootFlagEnvFile = "env-file" RootFlagTemplates = "templates" )
Common names for old root level flags
Variables ¶
This section is empty.
Functions ¶
func CreateLogger ¶
func CreateLogger(c *cli.Context, opts *CLIOpts, conf config.Type, streamsMode bool) (logger log.Modular, err error)
CreateLogger from a CLI context and a stream config.
func DelayShutdown ¶
DelayShutdown attempts to block until either: - The delay period ends - The provided context is cancelled - The process receives an interrupt or sigterm
func EnvFileAndTemplateFlags ¶ added in v4.31.0
EnvFileAndTemplateFlags represents env file and template flags that are used by some subcommands.
func PreApplyEnvFilesAndTemplates ¶ added in v4.31.0
PreApplyEnvFilesAndTemplates takes a cli context and checks for flags `env-file` and `templates` in order to parse and execute them before the CLI proceeds onto the next behaviour.
func ReadConfig ¶
func ReadConfig(c *cli.Context, cliOpts *CLIOpts, streamsMode bool) (mainPath string, inferred bool, conf *config.Reader)
ReadConfig attempts to read a general service wide config via a returned config.Reader based on input CLI flags. This includes applying any config overrides expressed by the --set flag.
func RunFlags ¶ added in v4.31.0
RunFlags is the full set of root level flags that have been deprecated and are now documented at each subcommand that requires them.
func RunManagerUntilStopped ¶
func RunManagerUntilStopped( c *cli.Context, opts *CLIOpts, conf config.Type, stopMgr *StoppableManager, stopStrm RunningStream, dataStreamClosedChan chan struct{}, ) error
RunManagerUntilStopped will run the provided HTTP server and block until either a provided stream stoppable is gracefully terminated (via the dataStreamClosedChan) or a signal is given to the process to terminate, at which point the provided HTTP server, the manager, and the stoppable is stopped according to the configured shutdown timeout.
func RunService ¶
RunService runs a service command (either the default or the streams subcommand).
Types ¶
type CLIOpts ¶
type CLIOpts struct { RootFlags *RootCommonFlags Stdout io.Writer Stderr io.Writer Version string DateBuilt string BinaryName string ProductName string DocumentationURL string ConfigSearchPaths []string Environment *bundle.Environment BloblEnvironment *bloblang.Environment SecretAccessFn func(context.Context, string) (string, bool) MainConfigSpecCtor func() docs.FieldSpecs // TODO: This becomes a service.Environment OnManagerInitialised func(mgr bundle.NewManagement, pConf *docs.ParsedConfig) error OnLoggerInit func(l log.Modular) (log.Modular, error) OnStreamInit StreamInitFunc CustomRunFlags []cli.Flag CustomRunExtractFn func(*cli.Context) error }
CLIOpts contains the available CLI configuration options.
func NewCLIOpts ¶
NewCLIOpts returns a new CLIOpts instance populated with default values.
func (*CLIOpts) ExecTemplate ¶
ExecTemplate parses a template and applies the CLI branding information to it.
func (*CLIOpts) RootCommonFlagsExtract ¶ added in v4.31.0
func (c *CLIOpts) RootCommonFlagsExtract(ctx *cli.Context)
RootCommonFlagsExtract attempts to read all common root flags from a cli context (presumed to be the root context).
type ErrExitCode ¶ added in v4.31.0
ErrExitCode is an error that could be returned by the cli application in order to indicate that a given exit code should be returned by the process.
func (*ErrExitCode) Error ¶ added in v4.31.0
func (e *ErrExitCode) Error() string
Error returns the underlying error string.
func (*ErrExitCode) Unwrap ¶ added in v4.31.0
func (e *ErrExitCode) Unwrap() error
Unwrap returns the underlying error.
type RootCommonFlags ¶ added in v4.31.0
type RootCommonFlags struct { Config string LogLevel string Set []string Resources []string Chilled bool Watcher bool }
RootCommonFlags represents a collection of flags that could be set at the root of the cli, even in the case of a subcommand being specified afterwards.
This is odd behaviour but we need to support it for backwards compatibility. And so, in cases where a subcommand needs to override these flags we use this type to extract flag arguments in order to ensure that root level flags are still honoured.
func (*RootCommonFlags) GetChilled ¶ added in v4.31.0
func (r *RootCommonFlags) GetChilled(c *cli.Context) bool
GetChilled attempts to read a config flag either from the current context, or falls back to whatever the root context set it to.
func (*RootCommonFlags) GetConfig ¶ added in v4.31.0
func (r *RootCommonFlags) GetConfig(c *cli.Context) string
GetConfig attempts to read a config flag either from the current context, or falls back to whatever the root context set it to.
func (*RootCommonFlags) GetLogLevel ¶ added in v4.31.0
func (r *RootCommonFlags) GetLogLevel(c *cli.Context) string
GetLogLevel attempts to read a config flag either from the current context, or falls back to whatever the root context set it to.
func (*RootCommonFlags) GetResources ¶ added in v4.31.0
func (r *RootCommonFlags) GetResources(c *cli.Context) []string
GetResources attempts to read a config flag either from the current context, or falls back to whatever the root context set it to.
func (*RootCommonFlags) GetSet ¶ added in v4.31.0
func (r *RootCommonFlags) GetSet(c *cli.Context) []string
GetSet attempts to read a config flag either from the current context, or falls back to whatever the root context set it to.
func (*RootCommonFlags) GetWatcher ¶ added in v4.31.0
func (r *RootCommonFlags) GetWatcher(c *cli.Context) bool
GetWatcher attempts to read a config flag either from the current context, or falls back to whatever the root context set it to.
type RunningStream ¶ added in v4.31.0
type RunningStream interface { ConnectionStatus() component.ConnectionStatuses Stop(ctx context.Context) error }
RunningStream represents a resource (a Benthos stream or a streams mode manager) that can be stopped.
type StoppableManager ¶
type StoppableManager struct {
// contains filtered or unexported fields
}
StoppableManager wraps a manager and API type that potentially outlives one or more dependent streams and encapsulates the logic for shutting them down within the deadline of a given context.
func CreateManager ¶
func CreateManager( c *cli.Context, cliOpts *CLIOpts, logger log.Modular, streamsMode bool, conf config.Type, mgrOpts ...manager.OptFunc, ) (stoppableMgr *StoppableManager, err error)
CreateManager from a CLI context and a stream config.
func (*StoppableManager) API ¶
func (s *StoppableManager) API() *api.Type
API returns the underlying api type.
func (*StoppableManager) Manager ¶
func (s *StoppableManager) Manager() *manager.Type
Manager returns the underlying manager type.
type StreamInitFunc ¶ added in v4.31.0
type StreamInitFunc func(s RunningStream) error
StreamInitFunc is an optional func to be called when a stream (or streams mode) is initialised.
type SwappableStopper ¶
type SwappableStopper struct {
// contains filtered or unexported fields
}
SwappableStopper wraps an active Stoppable resource in a mechanism that allows changing the resource for something else after stopping it.
func NewSwappableStopper ¶
func NewSwappableStopper(s RunningStream) *SwappableStopper
NewSwappableStopper creates a new swappable stopper resource around an initial stoppable.
func (*SwappableStopper) ConnectionStatus ¶ added in v4.31.0
func (s *SwappableStopper) ConnectionStatus() component.ConnectionStatuses
ConnectionStatus returns the connection status of the underlying stream.
func (*SwappableStopper) Replace ¶
func (s *SwappableStopper) Replace(ctx context.Context, fn func() (RunningStream, error)) error
Replace the resource with something new only once the existing one is stopped. In order to avoid unnecessary start up of the swapping resource we accept a closure that constructs it and is only called when we're ready.