app

package
v0.2.14-1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StopDeadline      = time.Minute
	StopWarningAfter  = time.Second * 10
	StartWarningAfter = time.Second * 10
)
View Source
var (
	// values of this vars will be defined while compilation
	AppName, GitCommit, GitBranch, GitState, GitSummary, BuildDate string
)

Functions

func MustComponent

func MustComponent[i any](app *App) i

MustComponent - generic version of app.MustComponent

func Version

func Version() string

func VersionDescription

func VersionDescription() string

Types

type App

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

App is the central part of the application It contains and manages all components

func (*App) AnySyncVersion

func (app *App) AnySyncVersion() string

func (*App) AppName

func (app *App) AppName() string

func (*App) ChildApp added in v0.2.0

func (app *App) ChildApp() *App

ChildApp creates a child container which has access to parent's components It doesn't call Start on any of the parent's components

func (*App) Close

func (app *App) Close(ctx context.Context) error

Close stops the application All components with ComponentRunnable implementation will be closed in the reversed order

func (*App) Component

func (app *App) Component(name string) Component

Component returns service by name If service with given name wasn't registered, nil will be returned

func (*App) ComponentNames

func (app *App) ComponentNames() (names []string)

ComponentNames returns all registered names

func (*App) IterateComponents added in v0.2.7

func (app *App) IterateComponents(fn func(Component))

IterateComponents iterates over all registered components. It's safe for concurrent use.

func (*App) MustComponent

func (app *App) MustComponent(name string) Component

MustComponent is like Component, but it will panic if service wasn't found

func (*App) Name

func (app *App) Name() string

Name returns app name

func (*App) Register

func (app *App) Register(s Component) *App

Register adds service to registry All components will be started in the order they were registered

func (*App) SetDeviceState

func (app *App) SetDeviceState(state int)

func (*App) SetVersionName added in v0.2.2

func (app *App) SetVersionName(v string)

SetVersionName sets the custom application version

func (*App) Start

func (app *App) Start(ctx context.Context) (err error)

Start starts the application All registered services will be initialized and started

func (*App) StartStat

func (app *App) StartStat() Stat

StartStat returns total time spent per comp for the last Start

func (*App) StopStat

func (app *App) StopStat() Stat

StopStat returns total time spent per comp for the last Close

func (*App) Version

func (app *App) Version() string

Version return app version

func (*App) VersionDescription

func (app *App) VersionDescription() string

VersionDescription return the full info about the build

func (*App) VersionName added in v0.2.2

func (app *App) VersionName() string

VersionName returns a string with the settled app version or auto-generated version if it didn't set

type Component

type Component interface {
	// Init will be called first
	// When returned error is not nil - app start will be aborted
	Init(a *App) (err error)
	// Name must return unique service name
	Name() (name string)
}

Component is a minimal interface for a common app.Component

type ComponentRunnable

type ComponentRunnable interface {
	Component
	// Run will be called after init stage
	// Non-nil error also will be aborted app start
	Run(ctx context.Context) (err error)
	// Close will be called when app shutting down
	// Also will be called when service return error on Init or Run stage
	// Non-nil error will be printed to log
	Close(ctx context.Context) (err error)
}

ComponentRunnable is an interface for realizing ability to start background processes or deep configure service

type ComponentStatable

type ComponentStatable interface {
	StateChange(state int)
}

type Stat

type Stat struct {
	SpentMsPerComp map[string]int64
	SpentMsTotal   int64
}

Directories

Path Synopsis
Package ldiff provides a container of elements with fixed id and changeable content.
Package ldiff provides a container of elements with fixed id and changeable content.
mock_ldiff
Package mock_ldiff is a generated GoMock package.
Package mock_ldiff is a generated GoMock package.

Jump to

Keyboard shortcuts

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