goapp

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

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

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 9 Imported by: 40

README

Go App

Build Status

  • Try to normalize how an application should start without providing any convention about how each steps should be used.
  • Provide an application container to store services

Features

  • Application container
  • Load configuration file (as string) and replace {{ env 'ENV' }} with env variables
  • Application lifecycle management: from load to exit

Documentation

Overview

The package try to normalize how an application should start without providing any convention about how each steps should be used.

The process will go through 6 steps:

  • Init: Initialize application: register flags, no logic should be done here
  • Register : Register components that does not required configuration settings
  • Config : Read configuration
  • Prepare : Defined main services from this configuration
  • Run : Run the main program loop, each function will be run in a goroutine
  • Exit : Register function call when the program will exit

Index

Constants

View Source
const (
	Init       = 10 // Initialize application: register flags, no logic should be done here
	Register   = 20 // Register components that does not required configuration settings
	Config     = 30 // Read configuration
	Prepare    = 40 // Defined main services from configuration
	Run        = 50 // Run the main program loop
	Exit       = 60 // Exit the program
	Terminated = 70 // Exit the program
)
View Source
const (
	Control_End   = 0 // process is stopped
	Control_Error = 1 // process generated an error
	Control_Stop  = 2 // process required to stop the application
	Control_Kill  = 3 // process required to kill the application
)

Variables

This section is empty.

Functions

func LoadConfigurationFromFile

func LoadConfigurationFromFile(path string) (string, error)

helper function to load a configuration file as template, and replace {{ env 'ENV_VARIABLE' }} with the variable from the environnement

func LoadConfigurationFromString

func LoadConfigurationFromString(data string) (string, error)

helper function to load a configuration string as template, and replace {{ env 'ENV_VARIABLE' }} with the variable from the environnement

func PanicIf

func PanicIf(b bool, message string)

func PanicOnError

func PanicOnError(err error)

func PanicUnless

func PanicUnless(b bool, message string)

Types

type App

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

The structure contains all services build by the AppFunc function, the service is initialized when get Get method is called.

func NewApp

func NewApp() *App

func (*App) Get

func (app *App) Get(name string) interface{}

func (*App) GetKeys

func (app *App) GetKeys() []string

func (*App) GetState

func (app *App) GetState() int

func (*App) GetString

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

func (*App) Has

func (app *App) Has(name string) bool

func (*App) IsTerminated

func (app *App) IsTerminated() bool

func (*App) Set

func (app *App) Set(name string, f AppFunc)

type AppFunc

type AppFunc func(app *App) interface{}

type GoroutineState

type GoroutineState struct {
	In    chan int // allow a goroutine to receive a stop/exit signal
	Out   chan int // allow a goroutine to send an exit command
	Error error    // store any error available while running the Process
}

func NewGoroutineState

func NewGoroutineState() *GoroutineState

func (*GoroutineState) Close

func (s *GoroutineState) Close()

type Lifecycle

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

func NewLifecycle

func NewLifecycle() *Lifecycle

func (*Lifecycle) Config

func (l *Lifecycle) Config(f LifecycleFun)

func (*Lifecycle) Exit

func (l *Lifecycle) Exit(f LifecycleFun)

func (*Lifecycle) Go

func (l *Lifecycle) Go(app *App) int

Start the different step, each LifecycleFun defined in the "run" step will be started in a dedicated goroutine. The Go function will return the exit code of the program

func (*Lifecycle) Init

func (l *Lifecycle) Init(f LifecycleFun)

func (*Lifecycle) Prepare

func (l *Lifecycle) Prepare(f LifecycleFun)

func (*Lifecycle) Register

func (l *Lifecycle) Register(f LifecycleFun)

func (*Lifecycle) Run

func (l *Lifecycle) Run(f LifecycleRunFun)

type LifecycleFun

type LifecycleFun func(app *App) error

Represents the function used to change states or start a process. Please note the process should be blocking as it will run inside a goroutine

type LifecycleRunFun

type LifecycleRunFun func(app *App, state *GoroutineState) error

Jump to

Keyboard shortcuts

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