aj

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

README

AppleJack

AppleJack (aj) is the shared foundation for all Holanet applications, whether they be client side desktop programs, or server side daemons. It combines several features from Nasin and CAMFISH for use in either of them, or in anything else you want.

Application Stack Diagram

[       nasin/tomo      ]
[        camfish        ]
[          aj           ]
[ go-cli ] [ go-service ]
[         go-util       ] 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterStage added in v0.2.0

func RegisterStage(index int, stage func(context.Context, Application) error) error

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

func RunCtx

func RunCtx(ctx context.Context, app Application) error

RunCtx runs the application using a custom context. The application is shut down once the context is cancelled, SIGINT is received, or Stop is called. Only one instance of Run/RunCtx may be remain running at a time.

func Stop

func Stop()

Stop stops the currently running application.

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

type Runnable

type Runnable interface {
	// Run runs 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.
	Run(ctx context.Context) error
}

Runnable is any object with a central, long-running routine.

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

Jump to

Keyboard shortcuts

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