Documentation
¶
Index ¶
- Constants
- Variables
- func AddBoolFlag(flagVar *bool, name string, defaultValue bool, usage string)
- func AddInitialAppContextOptions(options ...ContextOption)
- func AddOptions(options ...fx.Option)
- func AddStartContextOptions(options ...ContextOption)
- func AddStopContextOptions(options ...ContextOption)
- func AddStringFlag(flagVar *string, name string, defaultValue string, usage string)
- func DebugEnabled() bool
- func EnableCliRunnerMode(runnerProviders ...interface{})
- func Execute()
- func ExecuteContainedApp(ctx context.Context, b *Bootstrapper)
- func NewAppCmd(appName string, priorityOptions []fx.Option, regularOptions []fx.Option, ...)
- func Register(m *Module)
- type App
- type ApplicationConfig
- type ApplicationContext
- type ApplicationProperties
- type Bootstrapper
- func (b *Bootstrapper) AddInitialAppContextOptions(options ...ContextOption)
- func (b *Bootstrapper) AddOptions(options ...fx.Option)
- func (b *Bootstrapper) AddStartContextOptions(options ...ContextOption)
- func (b *Bootstrapper) AddStopContextOptions(options ...ContextOption)
- func (b *Bootstrapper) EnableCliRunnerMode(runnerProviders ...interface{})
- func (b *Bootstrapper) NewApp(cliCtx *CliExecContext, priorityOptions []fx.Option, ...) *App
- func (b *Bootstrapper) Register(m *Module)
- type BuildInfoMetadata
- type BuildInfoResolver
- type CliExecContext
- type CliOptions
- type CliRunner
- type CliRunnerEnabler
- type CliRunnerLifecycleHooks
- type CloudProperties
- type ContextOption
- type GatewayProperties
- type Module
- type ModuleBuildInfo
- type ModuleBuildInfoMap
- type OrderedCliRunner
- type ProfileProperties
- type Properties
Constants ¶
const ( FxCliRunnerGroup = "bootstrap_cli_runner" CliRunnerModuleName = "CLI Runner" )
const ( LowestPrecedence = int(^uint(0) >> 1) // max int HighestPrecedence = -LowestPrecedence - 1 // min int FrameworkModulePrecedenceBandwidth = 799 FrameworkModulePrecedence = LowestPrecedence - 200*(FrameworkModulePrecedenceBandwidth+1) AnonymousModulePrecedence = FrameworkModulePrecedence - 1 PriorityModulePrecedence = HighestPrecedence + 1 )
const ( AppConfigPrecedence TracingPrecedence ActuatorPrecedence ConsulPrecedence VaultPrecedence AwsPrecedence TlsConfigPrecedence RedisPrecedence DatabasePrecedence KafkaPrecedence OpenSearchPrecedence WebPrecedence SecurityPrecedence DebugPrecedence ServiceDiscoveryPrecedence DistributedLockPrecedence TenantHierarchyAccessorPrecedence TenantHierarchyLoaderPrecedence TenantHierarchyModifierPrecedence HttpClientPrecedence SecurityIntegrationPrecedence SwaggerPrecedence StartupSummaryPrecedence // CommandLineRunnerPrecedence invocation should happen after everything else, in case it needs functionality from any other modules CommandLineRunnerPrecedence )
const ( CliFlagActiveProfile = "active-profiles" CliFlagAdditionalProfile = "additional-profiles" CliFlagConfigSearchPath = "config-search-path" CliFlagDebug = "debug" EnvVarDebug = "DEBUG" )
const (
PropertyKeyApplicationName = "application.name"
)
Variables ¶
var ( BuildVersion = "Unknown" BuildTime = time.Now().Format(utils.ISO8601Seconds) BuildHash = "Unknown" BuildDeps = "github.com/cisco-open/go-lanai@main" )
var ( BuildInfo = BuildInfoMetadata{ Version: BuildVersion, BuildTime: utils.ParseTime(utils.ISO8601Seconds, BuildTime), Hash: BuildHash, Modules: ModuleBuildInfoMap{}, } BuildInfoMap map[string]interface{} )
Functions ¶
func AddInitialAppContextOptions ¶
func AddInitialAppContextOptions(options ...ContextOption)
func AddOptions ¶
func AddStartContextOptions ¶
func AddStartContextOptions(options ...ContextOption)
func AddStopContextOptions ¶
func AddStopContextOptions(options ...ContextOption)
func AddStringFlag ¶
AddStringFlag should be called before Execute() to register flags that are supported
func DebugEnabled ¶
func DebugEnabled() bool
DebugEnabled returns false by default, unless environment variable DEBUG is set or application start with --debug
func EnableCliRunnerMode ¶
func EnableCliRunnerMode(runnerProviders ...interface{})
EnableCliRunnerMode should be called before Execute(), otherwise it won't run. "runnerProviders" are standard FX lifecycle functions that typically used with fx.Provide(...) signigure of "runnerProviders", but it should returns CliRunner or OrderedCliRunner, otherwise it won't run
example of runner provider:
func myRunner(di OtherDependencies) CliRunner { return func(ctx context.Context) error { // Do your stuff return err } }
example of ordered runner provider:
func myRunner(di OtherDependencies) OrderedCliRunner { return bootstrap.OrderedCliRunner{ Precedence: 0, CliRunner: func(ctx context.Context) error { // Do your stuff return err }, } }
Using this pattern guarantees following things:
- The application is automatically shutdown after all lifecycle hooks finished
- The runner funcs are run after all other fx.Invoke
- All other "OnStop" are executed regardless if any hook function returns error (graceful shutdown)
- If any hook functions returns error, it reflected as non-zero process exit code
- Each cli runner are separately traced if tracing is enabled
- Any CliRunner without order is considered as having order 0
Note: calling this function repeatedly would override previous invocation (i.e. only the last invocation takes effect)
func Execute ¶
func Execute()
Execute run globally configured application. "globally configured" means Module and fx.Options added via package level functions. e.g. Register or AddOptions It adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.
func ExecuteContainedApp ¶
func ExecuteContainedApp(ctx context.Context, b *Bootstrapper)
ExecuteContainedApp is similar to Execute, but run with a separately configured Bootstrapper. In this mode, the bootstrapping process ignore any globally configured modules and options. This is usually called by test framework. Service developers normally don't use it directly
Types ¶
type App ¶
func (*App) EagerGetApplicationContext ¶
func (app *App) EagerGetApplicationContext() *ApplicationContext
EagerGetApplicationContext returns the global ApplicationContext before it becomes available for dependency injection Important: packages should typically get ApplicationContext via fx's dependency injection,
which internal application config are guaranteed. Only packages involved in priority bootstrap (appconfig, consul, vault, etc) should use this function for logging purpose
type ApplicationConfig ¶
type ApplicationContext ¶
ApplicationContext is a Context carries addition data for application. delegates all other context calls to the embedded Context.
func NewApplicationContext ¶
func NewApplicationContext(opts ...ContextOption) *ApplicationContext
func (*ApplicationContext) Config ¶
func (c *ApplicationContext) Config() ApplicationConfig
func (*ApplicationContext) Name ¶
func (c *ApplicationContext) Name() string
func (*ApplicationContext) String ¶
func (_ *ApplicationContext) String() string
func (*ApplicationContext) Value ¶
func (c *ApplicationContext) Value(key interface{}) interface{}
type ApplicationProperties ¶
type ApplicationProperties struct { Name string `json:"name"` Profiles ProfileProperties `json:"profiles"` }
type Bootstrapper ¶
type Bootstrapper struct {
// contains filtered or unexported fields
}
Bootstrapper stores application configurations for bootstrapping
func GlobalBootstrapper ¶
func GlobalBootstrapper() *Bootstrapper
GlobalBootstrapper returns globally configured Bootstrapper. This bootstrapper is the one that being used by Execute, any package-level function works against this instance
func NewBootstrapper ¶
func NewBootstrapper() *Bootstrapper
NewBootstrapper create a new Bootstrapper. Note: "bootstrap" package uses Singleton patterns for application bootstrap. Calling this function directly is not recommended
This function is exported for test packages to use
func (*Bootstrapper) AddInitialAppContextOptions ¶
func (b *Bootstrapper) AddInitialAppContextOptions(options ...ContextOption)
func (*Bootstrapper) AddOptions ¶
func (b *Bootstrapper) AddOptions(options ...fx.Option)
func (*Bootstrapper) AddStartContextOptions ¶
func (b *Bootstrapper) AddStartContextOptions(options ...ContextOption)
func (*Bootstrapper) AddStopContextOptions ¶
func (b *Bootstrapper) AddStopContextOptions(options ...ContextOption)
func (*Bootstrapper) EnableCliRunnerMode ¶
func (b *Bootstrapper) EnableCliRunnerMode(runnerProviders ...interface{})
EnableCliRunnerMode implements CliRunnerEnabler
func (*Bootstrapper) NewApp ¶
func (b *Bootstrapper) NewApp(cliCtx *CliExecContext, priorityOptions []fx.Option, regularOptions []fx.Option) *App
func (*Bootstrapper) Register ¶
func (b *Bootstrapper) Register(m *Module)
type BuildInfoMetadata ¶
type BuildInfoMetadata struct { Version string `json:"version"` BuildTime time.Time `json:"build-time"` Hash string `json:"hash"` Modules ModuleBuildInfoMap `json:"modules,omitempty"` }
func (*BuildInfoMetadata) ToMap ¶
func (m *BuildInfoMetadata) ToMap() map[string]interface{}
type BuildInfoResolver ¶
type BuildInfoResolver interface {
Resolve() BuildInfoMetadata
}
type CliExecContext ¶
type CliOptions ¶
type CliRunner ¶
func (CliRunner) WithOrder ¶
func (r CliRunner) WithOrder(order int) OrderedCliRunner
type CliRunnerEnabler ¶
type CliRunnerEnabler interface {
// EnableCliRunnerMode see bootstrap.EnableCliRunnerMode
EnableCliRunnerMode(runnerProviders ...interface{})
}
type CliRunnerLifecycleHooks ¶
type CliRunnerLifecycleHooks interface { Before(ctx context.Context, runner CliRunner) context.Context After(ctx context.Context, runner CliRunner, err error) context.Context }
CliRunnerLifecycleHooks provide instrumentation around CliRunners
type CloudProperties ¶
type CloudProperties struct {
Gateway GatewayProperties `json:"gateway"`
}
type GatewayProperties ¶
type Module ¶
type Module struct { Name string // Precedence basically govern the order or invokers between different Modules Precedence int // PriorityOptions are fx.Options applied before any regular Options PriorityOptions []fx.Option // Options is a collection fx.Option: fx.Provide, fx.Invoke, etc. Options []fx.Option // Modules is a collection of *Module that will also be initialized. // They are not necessarily sub-modules. During bootstrapping, all modules are flattened and Precedence are calculated at the end Modules []*Module }
func InitModule ¶
func InitModule(cliCtx *CliExecContext, app *App) *Module
InitModule returns the module that would run with highest priority
func MiscModules ¶
func MiscModules() []*Module
MiscModules returns the module that would run with various precedence
type ModuleBuildInfo ¶
type ModuleBuildInfoMap ¶
type ModuleBuildInfoMap map[string]ModuleBuildInfo
func (*ModuleBuildInfoMap) UnmarshalText ¶
func (m *ModuleBuildInfoMap) UnmarshalText(text []byte) error
type OrderedCliRunner ¶
func (OrderedCliRunner) Order ¶
func (r OrderedCliRunner) Order() int
type ProfileProperties ¶
type ProfileProperties struct { Active utils.CommaSeparatedSlice `json:"active"` Additional utils.CommaSeparatedSlice `json:"additional"` }
type Properties ¶
type Properties struct { Application ApplicationProperties `json:"application"` Cloud CloudProperties `json:"cloud"` }