brokkr

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 11 Imported by: 0

README

Brokkr

Coverage GitHub Super-Linter

About Brokkr

Brokkr provides a core entry point to manage the lifecycle of applications. However code structure based on composition and focus is to provide slim components that can be used independently.

In other words, focus on value - build prototypes, apps and API's.

Goals

Boosts your productivity by using reusable components in your project.

Principles
  • KISS - Keep it simple, stupid.
  • Don't repeat yourself - use what can be re-used.
  • Composition

Contribute

Getting Started

Create Brokkr entry point to manage the lifecycle, here simple bootstrap example:

package main

import (
	"github.com/clinknclank/brokkr"
)

func main() {
    // It's up to you how you load your configuration
    // yourAPIConfigurationStructure
    
    // Maybe you have gRPC or HTTP server that must be managed.
    // yourServer
    
    // And maybe you have metric collector that must be executed in background besides `yourServer`
    // yourMetricCollectorWatcher
    
    opts := []brokkr.Options{
        brokkr.SetForceStopTimeout(yourAPIConfigurationStructure.ServerShutdownTimeout), // Passing timeout to stop Brokkr.
        brokkr.AddBackgroundTasks(yourServer), // Passing your server.
        brokkr.AddBackgroundTasks(yourMetricCollectorWatcher), // Passing your metrics collector background process.
    }
    
    myApp := brokkr.NewBrokkr(opts...)
	
	// Execute your app that will have `yourServer` and `yourMetricCollectorWatcher`
	// in controlled gorutine as background process, which will be managed by same main loop inside `Brokkr`.
	if err := myApp.Start(); err != nil {
		panic(err)
	}
}
Run tests
go test -v --race $(go list ./... | (grep -v /vendor/) | (grep -v internal/test/bdd/integration_tests))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Brokkr

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

Brokkr manages the lifecycle of an application. This structure is responsible for overseeing the processes and tasks that constitute the app, and provides mechanisms for controlled starts, stops, and signal handling.

func NewBrokkr

func NewBrokkr(opts ...Options) (b *Brokkr)

NewBrokkr framework instance

func (*Brokkr) Start

func (c *Brokkr) Start() error

Start initializes and runs the Brokkr's main loop. It launches the background tasks and monitors for interrupt signals. In the event of an interrupt or an error in a background task, the function will begin shutdown procedures.

func (*Brokkr) Stop

func (c *Brokkr) Stop() error

Stop in graceful mode and terminate all background tasks.

type Options

type Options func(o *Brokkr)

Options sets of configurations for Brokkr.

func AddBackgroundTasks

func AddBackgroundTasks(bt ...background.Process) Options

AddBackgroundTasks that will be executed in background of main loop.

func SetForceStopTimeout

func SetForceStopTimeout(t time.Duration) Options

SetForceStopTimeout redefines force shutdown timeout.

Jump to

Keyboard shortcuts

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