Documentation
¶
Index ¶
- func RegisterStage(index int, stage func(context.Context, Application) error) error
- func Run(app Application) error
- func RunCtx(ctx context.Context, app Application) error
- func Stop()
- type Application
- type Cleanupable
- type Described
- type Initializable
- type Named
- type RunShutdownable
- type RunShutdownableShim
- type Runnable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterStage ¶ added in v0.2.0
RegisterStage registers a function to be called when an application is starting up or shutting down. This is for when you want to extend AppleJack itself.
Standard phases:
- 10: Flag parsing
- 50: Configuration
- 60: Initialization
- 70: Running
- 80: Shutdown
- 90: Cleanup
Indices 70-80 are unavailable for use, as the application is running during this time.
func Run ¶
func Run(app Application) error
Run runs the application. Capabilities are probed using the above interfaces. The application is shut down once SIGINT is received, or Stop is called. Only one instance of Run/RunCtx may be remain running at a time.
The application's methods are called in this order:
- Configure
- Init
- Run
- Shutdown
- Cleanup
Types ¶
type Application ¶
type Application interface {
// ID returns a unique app identifier. This should be a domain
// name in reverse. Here are some examples:
//
// com.example.SomeApp
// xyz.holanet.Garden
ID() string
}
Application is a basic application interface.
func Current ¶ added in v0.3.0
func Current() Application
Current returns the currently running application. If there is no application running, it returns nil. This function is goroutine safe.
type Cleanupable ¶
type Cleanupable interface {
// Cleanup performs cleanup operations such as freeing resources associated
// with the object. It must return when or before the context expires, and
// must return ctx.Err if there is no other error to be returned.
Cleanup(ctx context.Context) error
}
Cleanupable is any object that must be cleaned up after it has stopped for good. Actors which implement this interface will be cleaned up after they are deleted from the environment.
type Described ¶
type Described interface {
// Description returns a user-readable description of the application.
Description() string
}
Described is an object with a user-readable description.
type Initializable ¶
type Initializable interface {
// Init initializes the object. It must return before the context
// expires, and must return ctx.Err if there is no other error to be
// returned. If Init returns an error, the object must be treated as
// invalid and any process which depends on it should be shut down.
Init(ctx context.Context) error
}
Initializable is any object that must be initialized before use. Objects which implement this interface will be initialized during the initialization phase, or when they are added.
type Named ¶
type Named interface {
// Name returns a user-readable name for the application.
Name() string
}
Named is an object with a user-readable name.
type RunShutdownable ¶
type RunShutdownable interface {
// Run is similar to [Runnable.Run], but takes no context and blocks
// until Shutdown has run and exited. It may also return when something
// goes wrong and it cannot continue, in which case it must return a
// non-nil error explaining why. Shutdown does not need to be called in
// the latter case.
Run() error
// Shutdown shuts down the actor. It must unblock Run in all cases even
// on failure, context expiration, etc. Shutdown must return when or
// before the context expires, and must return ctx.Err if there is no
// other error to be returned. If Shutdown returns any error, the object
// must be treated as invalid and any other process which depends on it
// should be shut down.
Shutdown(ctx context.Context) error
}
RunShutdownable is any object that needs a context in order to shut down. Actors which implement this interface cannot implement the Runnable interface. This can be used to run an http.Server as an actor.
type RunShutdownableShim ¶
type RunShutdownableShim struct {
RunShutdownable
// contains filtered or unexported fields
}
RunShutdownableShim converts an underlying RunShutdownable into a normal Runnable.
func (*RunShutdownableShim) Run ¶
func (this *RunShutdownableShim) Run(ctx context.Context) error
Source Files
¶
- aj.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package config provides a configuration system for applications.
|
Package config provides a configuration system for applications. |
|
Package event provides a system for broadcasting events to multiple event handlers.
|
Package event provides a system for broadcasting events to multiple event handlers. |
|
examples
|
|
|
config
command
|
|
|
internal
|
|