Skip to content

Easy orchestration and management of services at runtime!

License

Notifications You must be signed in to change notification settings

lukejoshuapark/app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

app

Easy orchestration and management of services at runtime!

Usage Example

package main

import (
	"fmt"

	"github.com/lukejoshuapark/app"
)

func main() {
	app.Run(&App{})
}

// --

type App struct{}

func (a *App) Services() ([]app.Service, error) {
	return []app.Service{
		NewWaitingService(),
	}, nil
}

// --

type WaitingService struct{}

var _ app.Service = &WaitingService{}

func NewWaitingService() *WaitingService {
	return &WaitingService{}
}

func Run(ctx context.Context) error {
	fmt.Println("I'm just going to sit here until the application terminates...")
	<-ctx.Done()

	fmt.Println("Goodbye!")
	return nil
}

Behavior

This module provides a lightweight but powerful runtime service management layer. It has two concepts:

  • App - A type that implements the Services method. It simply constructs and returns all the runtime services that make up the application.

  • Service An actual runtime service. A service can do whatever it likes, as long as it:

    • Returns a nil error as soon as possible when the context provided to it ends.

    • Returns an error when something unrecoverable occurs.

Passing your implementation of app.App to app.Run starts the application. The runtime layer handles termination signals by cancelling the context provided to each service.


Icons made by justicon from www.flaticon.com.

About

Easy orchestration and management of services at runtime!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages