toho

package module
v0.0.0-...-d015374 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 12 Imported by: 0

README

toho

Documentation

Index

Constants

View Source
const DefaultTimeout = 15 * time.Second

DefaultTimeout is the default timeout for starting or stopping an application. It can be configured with the StartTimeout and StopTimeout options.

Variables

This section is empty.

Functions

This section is empty.

Types

type Core

type Core interface {
	// Init is used to configure application core.
	Init(*CoreOptions) error

	// Start starts the application.
	Start(context.Context) error

	// Stop gracefully stops the application.
	Stop(context.Context) error

	// Wait for termination of interrupt signals.
	Wait() <-chan os.Signal
}

Core interface defines the methods for initializing and starting the application.

type CoreOptions

type CoreOptions struct {
	App app.App

	ConfigPointer any
	LogPointer    any

	Options []any

	StartTimeout time.Duration
	StopTimeout  time.Duration
}

CoreOptions struct holds the configuration options for the Core interface.

type Option

type Option func(o *options)

Option is an application option.

func AfterStart

func AfterStart(fn func(context.Context) error) Option

AfterStart run functions after app starts.

func AfterStop

func AfterStop(fn func(context.Context) error) Option

AfterStop run functions after app stops.

func AppCore

func AppCore(s Core) Option

AppCore with app core.

func AppInfo

func AppInfo(opts ...app.Option) Option

AppInfo with app info.

func BeforeStart

func BeforeStart(fn func(context.Context) error) Option

BeforeStart run functions before app starts.

func BeforeStop

func BeforeStop(fn func(context.Context) error) Option

BeforeStop run functions before app stops.

func Context

func Context(ctx context.Context) Option

Context with app context.

func Logger

func Logger(l any) Option

Logger with app logger.

func Options

func Options(opts ...any) Option

Options with any options for the app.

func StartTimeout

func StartTimeout(t time.Duration) Option

StartTimeout with app start timeout.

func StopTimeout

func StopTimeout(t time.Duration) Option

StopTimeout with app stop timeout.

type TohoApp

type TohoApp[C, L any] struct {
	// contains filtered or unexported fields
}

TohoApp defines a application components lifecycle manager. [C] defines type of the configuration struct for the application. [L] defines type of the logger for the application.

func New

func New(opts ...Option) *TohoApp[struct{}, *slog.Logger]

func NewC

func NewC[C any](opts ...Option) *TohoApp[C, *slog.Logger]

func NewCL

func NewCL[C, L any](opts ...Option) *TohoApp[C, L]

func NewL

func NewL[L any](opts ...Option) *TohoApp[struct{}, L]

func (*TohoApp[C, L]) AppInfo

func (a *TohoApp[C, L]) AppInfo() app.Info

func (*TohoApp[C, L]) Config

func (a *TohoApp[C, L]) Config() C

func (*TohoApp[C, L]) Logger

func (a *TohoApp[C, L]) Logger() L

func (*TohoApp[C, L]) Start

func (a *TohoApp[C, L]) Start() error

Start executes all OnStart hooks registered with the application's Lifecycle.

func (*TohoApp[C, L]) Stop

func (a *TohoApp[C, L]) Stop() error

Stop gracefully stops the application.

func (*TohoApp[C, L]) Wait

func (a *TohoApp[C, L]) Wait() <-chan error

Wait blocks application until termination.

Jump to

Keyboard shortcuts

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