This stable version.
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
}
- Signals for graceful shutdown
- Init functions
- Components
- Service startup
- Customer logger
$ go get github.com/mantyr/starter
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()