Documentation ¶
Overview ¶
Package app provides an opinionated common infrastructure to application structure.
Index ¶
- Constants
- Variables
- func AddCleanup(ctx context.Context, f func())
- func AddCleanupSignal(s ...task.Event)
- func Run(main task.Task)
- func Usage(ctx context.Context, message string, args ...interface{})
- func VerbMain(ctx context.Context) error
- func WaitForCleanup(ctx context.Context) bool
- type Action
- type AppFlags
- type ExitCode
- type LogFlags
- type ProfileFlags
- type Verb
- type VersionSpec
Constants ¶
const ( // FatalSeverity Is the level at which logging causes panics. FatalSeverity = log.Fatal )
Variables ¶
var ( // Name is the full name of the application Name string // ExitFuncForTesting can be set to change the behaviour when there is a command line parsing failure. // It defaults to os.Exit ExitFuncForTesting = os.Exit // ShortHelp should be set to add a help message to the usage text. ShortHelp = "" // ShortUsage is usage text for the additional non-flag arguments. ShortUsage = "" UsageFooter = "" // Version holds the version specification for the application. // The default version is the one defined in version.cmake. // If valid a command line option to report it will be added automatically. Version VersionSpec // Restart is the error to return to cause the app to restart itself. Restart = fault.Const("Restart") )
var ( // CleanupTimeout is the time to wait for all cleanup signals to fire when shutting down. CleanupTimeout = time.Second )
Functions ¶
func AddCleanup ¶
AddCleanup calls f when the context is cancelled. Application will wait (for a maximum of CleanupTimeout) for f to complete before terminiating the application.
func AddCleanupSignal ¶
AddCleanupSignal adds a signal the app should wait on when shutting down. The signal will automatically be dropped when it is fired, no need unregister it.
func Run ¶
Run performs all the work needed to start up an application. It parsers the main command line arguments, builds a primary context that will be cancelled on exit runs the provided task, cancels the primary context and then waits for either the maximum shutdown delay or all registered signals whichever comes first.
func Usage ¶
Usage prints message with the formatting args to stderr, and then prints the command usage information and terminates the program.
func WaitForCleanup ¶
WaitForCleanup waits for all the cleanup signals to fire, or the cleanup timeout to expire, whichever comes first.
Types ¶
type Action ¶
type Action interface { // Run executes the action. Run(ctx context.Context, flags flag.FlagSet) error }
Action is the interface for verb actions that can be run. Exported fields will be exposed as flags for the verb. Use the `help` tag to expose a flag description.
type AppFlags ¶
type AppFlags struct { Version bool `help:"_display the application version"` Log LogFlags Profile ProfileFlags }
type ExitCode ¶
type ExitCode int
ExitCode is the type for named return values from the application main entry point.
const ( // SuccessExit is the exit code for succesful exit. SuccessExit ExitCode = iota // FatalExit is the exit code if something logs at a fatal severity (critical or higher by default) FatalExit // UsageExit is the exit code if the usage function was invoked UsageExit // RestartExit is the exit code if the app should be restarted. RestartExit )
type ProfileFlags ¶
type ProfileFlags struct {
CPU string `help:"_write cpu profile to file"`
}
type Verb ¶
type Verb struct { Name string // The name of the command ShortHelp string // Help for the purpose of the command ShortUsage string // Help for how to use the command Action Action // The verb's action. Must be set. // contains filtered or unexported fields }
Verb holds information about a runnable api command.
func AddVerb ¶
AddVerb adds a new verb to the supported set, it will panic if a duplicate name is encountered. v is returned so the function can be used in a fluent-style.
func FilterVerbs ¶
FilterVerbs returns the filtered list of verbs who's names match the specified prefix.
func (*Verb) Add ¶
Add adds a new verb to the supported set, it will panic if a duplicate name is encountered.
type VersionSpec ¶
type VersionSpec struct { // Major version, the version structure is in valid if <0 Major int // Minor version, not used if <0 Minor int // Point version, not used if <0 Point int // The build identifier, not used if an empty string Build string }
VersionSpec is the structure for the version of an application.
func (VersionSpec) Format ¶
func (v VersionSpec) Format(f fmt.State, c rune)
Format implements fmt.Formatter to print the version.
func (VersionSpec) GreaterThan ¶ added in v0.5.1
func (v VersionSpec) GreaterThan(o VersionSpec) bool
GreaterThan returns true if v is greater than o.
func (VersionSpec) IsValid ¶
func (v VersionSpec) IsValid() bool
IsValid reports true if the VersionSpec is valid, ie it has a Major version.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package auth provides simple token based, stream authorization functions.
|
Package auth provides simple token based, stream authorization functions. |
Package benchmark provides benchmarking facilities to the standard application system.
|
Package benchmark provides benchmarking facilities to the standard application system. |
Package flag provides extended support for flag parsing.
|
Package flag provides extended support for flag parsing. |
Package layout is used to find parts of the application package to load or run.
|
Package layout is used to find parts of the application package to load or run. |