Skip to content
/ starter Public

This is a package for organizing the launch of services inside the application with convenient initialization of components.

License

Notifications You must be signed in to change notification settings

mantyr/starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Starter

Build Status GoDoc Go Report Card Software License

This stable version.

Description

This is a package for organizing the launch of services inside the application with convenient initialization of components.

  • The component can be initialized
  • The services can be started and stopped
import (
	"github.com/urfave/cli/v2"
)

type Component interface {
	Name() string
	Init(ctx *cli.Context) error
	Destroy(ctx *cli.Context) error
}

type Service interface {
	Name() string
	Start(ctx *cli.Context) error
	Stop(ctx *cli.Context) error
}

Supports

  • Signals for graceful shutdown
  • Init functions
  • Components
  • Service startup
  • Customer logger

Installation

$ go get github.com/mantyr/starter

Example

package main

import (
	"syscall"

	"github.com/urfave/cli/v2"
	"github.com/mantyr/starter"

	"service1"
	"service2"
)

func main() {
	var ctx cli.Context
	ctx.Set("server.gracefulstop.duration", "30m")

	s1, err := service1.New()
	if err != nil {
		panic(err)
	}
	s2, err := service2.New()
	if err != nil {
		panic(err)
	}

	s := starter.New()
	s.Signals(
		syscall.SIGINT,
		syscall.SIGTERM,
	).Init(
		ctx,
		db,
		s1,
		s2,
		starter.NewComponent("service3").SetInit(func() error{return nil}).SetDestroy(func() error{return nil}),
	).RunServices(
		ctx,
		s1,
		s2,
	).Wait()

Author

Oleg Shevelev

About

This is a package for organizing the launch of services inside the application with convenient initialization of components.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages