deamon

package module
v0.0.0-...-7b69238 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2021 License: BSD-3-Clause Imports: 4 Imported by: 0

README

DEAMON.go

I found myself keep writing the same signal intrupt code over and over again, so I created this.

INSTALLATION

do the either of options:

  • you can even copy the code in deamon.go to your project directly
  • or run go get github.com/alinz/deamon.go inside your go project

USAGE

simply in your main program use it as follows;


func main() {
    ctx := context.Background()

    err := deamon.Summoning(ctx, func (ctx context.Context, summonType deamon.SummonType) error {
        switch summonType {
            case deamon.Call:
                // only happens once at the start, go point for initializing
                // all long lived objects here
            case deamon.Recall:
                // program requested to be reloaded
                // might be a good point to reload config files here
            case deamon.Kill:
                // program requested to be killed
                // do the neccessary clean up here
        }

        return nil
    })

    if err != nil {
        log.Println(err)
        os.Exit(1)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Summoning

func Summoning(ctx context.Context, summoner Summoner) error

Types

type SummonType

type SummonType int
const (
	Call   SummonType // Call happens once at the beginning of the program
	Recall            // Recall happens when the program is requested to be reloaded
	Kill              // Kill happens when the program is killed
)

type Summoner

type Summoner interface {
	Summon(ctx context.Context, summonType SummonType) error
}

type SummonerFunc

type SummonerFunc func(ctx context.Context, summonType SummonType) error

func (SummonerFunc) Summon

func (f SummonerFunc) Summon(ctx context.Context, summonType SummonType) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL