app

package module
v0.0.0-...-31dbb72 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0, BSD-2-Clause Imports: 20 Imported by: 108

Documentation

Index

Constants

View Source
const (
	DefaultFlagSetName = "appConfig"
)

Variables

This section is empty.

Functions

func NewLoggerFromConfig

func NewLoggerFromConfig(cfg *LoggerConfig) (log.Logger, error)

Types

type App

type App struct {
	log.Logger
	// contains filtered or unexported fields
}

func New

func New(name string, version string, optionalOptions ...Option) *App

func (*App) AdditionalConfigs

func (a *App) AdditionalConfigs() map[string]*configuration.Configuration

func (*App) AdditionalFlagSets

func (a *App) AdditionalFlagSets() map[string]*flag.FlagSet

func (*App) Config

func (a *App) Config() *configuration.Configuration

func (*App) Daemon

func (a *App) Daemon() daemon.Daemon

func (*App) FlagSet

func (a *App) FlagSet() *flag.FlagSet

func (*App) ForEachComponent

func (a *App) ForEachComponent(f ComponentForEachFunc)

ForEachComponent calls the given ComponentForEachFunc on each loaded component.

func (*App) Info

func (a *App) Info() *Info

func (*App) IsComponentEnabled

func (a *App) IsComponentEnabled(identifier string) bool

IsComponentEnabled returns whether the component is enabled.

func (*App) Parameters

func (a *App) Parameters() *ParametersApp

func (*App) Run

func (a *App) Run()

func (*App) Shutdown

func (a *App) Shutdown()

func (*App) Start

func (a *App) Start()

type Callback

type Callback func() error

Callback is a function called without any arguments.

type Component

type Component struct {
	log.Logger

	// The name of the component.
	Name string
	// The config parameters for this component.
	Params *ComponentParams
	// The function to call to initialize the component dependencies.
	DepsFunc interface{}
	// InitConfigParams gets called in the init stage of app initialization.
	// This can be used to provide config parameters even if the component is disabled.
	InitConfigParams InitConfigParamsFunc
	// IsEnabled gets called to check whether the component is enabled.
	IsEnabled IsEnabledFunc
	// Provide gets called in the provide stage of app initialization (enabled components only).
	Provide ProvideFunc
	// Configure gets called in the configure stage of app initialization (enabled components only).
	Configure Callback
	// Run gets called in the run stage of app initialization (enabled components only).
	Run Callback
	// WorkerPool gets configured and started automatically for each component (enabled components only).
	WorkerPool *workerpool.WorkerPool
	// contains filtered or unexported fields
}

Component is something which extends the App's capabilities.

func (*Component) App

func (c *Component) App() *App

func (*Component) Daemon

func (c *Component) Daemon() daemon.Daemon

func (*Component) Identifier

func (c *Component) Identifier() string

type ComponentForEachFunc

type ComponentForEachFunc func(component *Component) bool

ComponentForEachFunc is used in ForEachComponent. Returning false indicates to stop looping.

type ComponentParams

type ComponentParams struct {
	// Handler to add configuration parameters to the default config.
	Params map[string]any
	// Handler to add configuration parameters to the additional configs.
	AdditionalParams map[string]map[string]any
	// The configuration values to mask.
	Masked []string
}

ComponentParams defines the parameters configuration of a component.

type ConfigurationSet

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

func NewConfigurationSet

func NewConfigurationSet(
	configName string,
	filePathFlagName string,
	filePathFlagProvideName string,
	flagSetName string,
	loadOnlyIfFlagDefined bool,
	loadFlagSet bool,
	loadEnvVars bool,
	defaultConfigPath string,
	shortHand string) *ConfigurationSet

type ConfigurationSets

type ConfigurationSets []*ConfigurationSet

func (ConfigurationSets) ConfigsMap

func (ConfigurationSets) FlagSets

func (c ConfigurationSets) FlagSets() []*flag.FlagSet

func (ConfigurationSets) FlagSetsMap

func (c ConfigurationSets) FlagSetsMap() map[string]*flag.FlagSet

type Info

type Info struct {
	Name                string
	Version             string
	LatestGitHubVersion string
}

Info provides information about the app.

type InitComponent

type InitComponent struct {
	*Component

	NonHiddenFlags []string
	// Init gets called in the initialization stage of the app.
	Init InitFunc
	// The additional configs this InitComponent brings to the app.
	AdditionalConfigs []*ConfigurationSet
}

InitComponent is the module initializing configuration of the app. An App can only have one of such modules.

type InitConfigParamsFunc

type InitConfigParamsFunc func(c *dig.Container) error

InitConfigParamsFunc gets called with a dig.Container.

type InitFunc

type InitFunc func(application *App) error

InitFunc gets called as the initialization function of the app.

type IsEnabledFunc

type IsEnabledFunc func(c *dig.Container) bool

IsEnabledFunc gets called to check whether the Compoment is enabled. It gets called with a dig.Container and returns true if the Compoment is enabled.

type LoggerConfig

type LoggerConfig struct {
	// Name is the optional name of the logger instance. All log messages are prefixed with that name.
	Name string `default:"" json:"name" usage:"the optional name of the logger instance. All log messages are prefixed with that name."`
	// Level is the minimum enabled logging level.
	// The default is "info".
	Level string `default:"info" json:"level" usage:"the minimum enabled logging level"`
	// TimeFormat sets the logger's timestamp format. Valid values are "layout", "ansic", "unixdate", "rubydate",
	// "rfc822", "rfc822z", "rfc850", "rfc1123", "rfc1123z", "rfc3339", "rfc3339nano", "kitchen", "stamp", "stampmilli",
	// "stampmicro", "stampnano", "datetime", "dateonly", "timeonly" and "iso8601".
	// The default is "rfc3339".
	TimeFormat string `` /* 182-byte string literal not displayed */
	// OutputPaths is a list of URLs, file paths or stdout/stderr to write logging output to.
	// The default is ["stdout"].
	OutputPaths []string `default:"stdout" json:"outputPaths" usage:"a list of file paths or stdout/stderr to write logging output to"`
}

LoggerConfig holds the settings to configure a logger instance.

type Option

type Option func(opts *Options)

Option is a function setting a Options option.

func WithComponents

func WithComponents(components ...*Component) Option

WithComponents sets the components.

func WithDaemon

func WithDaemon(d daemon.Daemon) Option

WithDaemon sets the used daemon.

func WithInitComponent

func WithInitComponent(initComponent *InitComponent) Option

WithInitComponent sets the init component.

func WithUsageText

func WithUsageText(usageText string) Option

WithUsageText overwrites the default usage text of the app.

func WithVersionCheck

func WithVersionCheck(owner string, repository string) Option

WithVersionCheck enables the GitHub version check.

type Options

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

Options defines options for an App.

type ParametersApp

type ParametersApp struct {
	CheckForUpdates bool `default:"true" usage:"whether to check for updates of the application or not"`
}

type ProvideFunc

type ProvideFunc func(c *dig.Container) error

ProvideFunc gets called with a dig.Container.

Directories

Path Synopsis
components
utils module

Jump to

Keyboard shortcuts

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