micron

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 8 Imported by: 0

README

Micron

Go Report License

Minimalistic app container for managing runnable components with a dead simple interface.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func NewApp

func NewApp(opts ...Option) *App

func (*App) Close

func (a *App) Close(c Closer) *App

Close registers Closer component. Closer components are invoked during application Stop process.

func (*App) Init

func (a *App) Init(i Initializer) *App

Init registers Initializer component. Initializer components are invoked during application Start process before Run happens.

func (*App) OnPanic

func (a *App) OnPanic(f func(any))

OnPanic registers a callback function called in case of panic. Usually used to notify an external system (slack/email/sentry/etc) about unhandled issue in the running app. App instance can have only one panic callback. Every OnPanic invocation overwrites previously registered handler.

func (*App) Register

func (a *App) Register(component any) *App

Register is a shorthand function to register a component that implements multiple micron lifecycle hooks.

func (*App) Run

func (a *App) Run(r Runner) *App

Run registers Runner component.

func (*App) Start

func (a *App) Start(ctx context.Context) error

func (*App) Stop

func (a *App) Stop(ctx context.Context) error

Stop will attempt to close all the components resources before exiting. It can be explicitly invoked whenever you want, otherwise it will be called automatically by the App instance in one of the following cases: - after all the runners return - when the context passed to Start is canceled - after a SIGNINT or SIGTERM signal is received

It's safe to call Stop multiple times, but only the first call will do the actual work. Please note that Stop is not guaranteed to be called in case of a panic.

type CloseFunc

type CloseFunc func(ctx context.Context) error

func (CloseFunc) Close

func (cf CloseFunc) Close(ctx context.Context) error

type Closer

type Closer interface {
	Close(ctx context.Context) error
}

type InitFunc

type InitFunc func(ctx context.Context) error

func (InitFunc) Init

func (f InitFunc) Init(ctx context.Context) error

type Initializer

type Initializer interface {
	Init(ctx context.Context) error
}

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
}

type Option

type Option func(*App)

func WithLogger

func WithLogger(log Logger) Option

func WithStopTimeout added in v0.0.2

func WithStopTimeout(timeout time.Duration) Option

type RunFunc

type RunFunc func(ctx context.Context) error

func (RunFunc) Run

func (rf RunFunc) Run(ctx context.Context) error

type Runner

type Runner interface {
	Run(ctx context.Context) error
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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