application

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

logo

application

Application Manager


Package allows you to perform a phased launch of the application.


Install application

  1. Load the package into the project
go get github.com/auvitly/application
  1. Import the package at the place of use
import "github.com/auvitly/application"

Documentation

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongState = errors.New("the method called does not match the state")

	ErrInitFailure          = errors.New("initialization error")
	ErrInitTimeout          = errors.New("initialization timeout")
	ErrInitContextDeadline  = errors.New("deadline context")
	ErrInitConstructorPanic = errors.New("panic in constructor")

	ErrRunContextDeadline = errors.New("running application stopped dua deadline context")
	ErrRunPanic           = errors.New("running application stopped dua panic")
	ErrRunService         = errors.New("running application stopped dua service error")

	ErrTerminateTimeout = errors.New("terminate attempt failed due to timeout")
)

Functions

func Recover added in v1.1.0

func Recover()

Recover - global method for catching application panics

Types

type Application

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

Application - implements the start of services and their completion

func New

func New(config *Config) *Application

New - creating an application instance

func (*Application) Init

func (app *Application) Init(ctx context.Context, signals ...os.Signal) (err error)

Init - performs initialization of registered constructors

func (*Application) RegistrationResource

func (app *Application) RegistrationResource(resources ...io.Closer) (err error)

RegistrationResource - registering resource Destructors

func (*Application) RegistrationService

func (app *Application) RegistrationService(constructors ...Constructor) (err error)

RegistrationService - registering Constructor with internally initialized dependencies

func (*Application) Run

func (app *Application) Run(ctx context.Context) (err error)

Run - launching the ready application

func (*Application) SetLogger added in v1.1.0

func (app *Application) SetLogger(logger Logger)

SetLogger sets the logger for package output

func (*Application) Shutdown

func (app *Application) Shutdown() (err error)

Shutdown - shutdown the application

type Config

type Config struct {
	InitialisationTimeout time.Duration `json:"initialisation_timeout"`
	TerminationTimeout    time.Duration `json:"termination_timeout"`
	EnableDebugStack      bool          `json:"enable_debug_stack"`
}

type Constructor

type Constructor func(ctx context.Context, app *Application) (Service, error)

type Logger added in v1.1.0

type Logger interface {
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Print(v ...interface{})
	Println(v ...interface{})
	Printf(format string, v ...interface{})
}

Logger is standard logger interface

type Service

type Service interface {
	Serve() error
	io.Closer
}

type State

type State int
const (
	StateInit State = iota
	StateReady
	StateRunning
	StateShutdown
	StateOff
)

func (State) String

func (s State) String() string

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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