Getting started

Getting started

Introduction

To manage service instances correctly, all these requirements are mandatory:

  • All service instances only work when their dependencies are ready.
  • All service instances onnly stop when the ones depends on them are finished.

Gobs control how an application will start. It manage all service instances in 5 life-cycles: init, setup, start, stop. For these characteristics, we need to know:

  1. How to create and run the Gobs
  2. How to setup a service instance and put to gobs

But first, let’s install the Gobs to your project.

Installation

go get github.com/xarest/gobs

Quick start

main.go
package main

import (
	"context"
	"fmt"

	"github.com/xarest/gobs"
)

type API struct{}

func (a *API) Start(ctx context.Context) error {
	fmt.Println("API started")
	return nil
}

func (a *API) Stop(ctx context.Context) error {
	fmt.Println("API stopped")
	return nil
}

func main() {
	ctx := context.Background()
	bs := gobs.NewBootstrap()
	bs.AddOrPanic(&API{})
	bs.Start(ctx)
}

The output of the program

API started
API stopped

For the details of each step, please go to create and run the Gobs