mantyr / starter

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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
}

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

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", 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.

License:MIT License


Languages

Language:Go 100.0%