GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Why Go
  • Case Studies
  • Use Cases
  • Security
  • Learn
  • Effective Go
  • Go User Manual
  • Standard library
  • Release Notes
  • API
  • Packages
  • Recorded Talks
  • Meetups
  • Conferences

This view

  • Original page
  • New address

GeezerVison is showing pkg.go.dev — death package - gopkg.in/vrecan/death.v1 - Go Packages

Notice  The highest tagged major version is v3.

Details

  • unchecked Valid go.mod file

    The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.

  • checked Redistributable license

    Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.

  • unchecked Tagged version

    Modules with tagged versions give importers more predictable builds.

  • unchecked Stable version

    When a project reaches major version v1 it is considered stable.

  • Learn more about best practices

Repository

github.com/vrecan/death

Links

  • Open Source Insights Logo Open Source Insights

README ¶

Death Build Status

Simple library to make it easier to manage the death of your application.

Get The Library

go get github.com/vrecan/death

Use The Library

package main

import (
	DEATH "github.com/vrecan/death"
	SYS "syscall"
)

func main() {
	death := DEATH.NewDeath(SYS.SIGINT, SYS.SIGTERM) //pass the signals you want to end your application
	//when you want to block for shutdown signals
	death.WaitForDeath() // this will finish when a signal of your type is sent to your application
}
Close Other Objects On Shutdown

One simple feature of death is that it can also close other objects when shutdown starts

package main

import (
	DEATH "github.com/vrecan/death"
	SYS "syscall"
	"io"
)

func main() {
	death := DEATH.NewDeath(SYS.SIGINT, SYS.SIGTERM) //pass the signals you want to end your application
	objects := make([]io.Closer, 0)

	objects = append(objects, &NewType{}) // this will work as long as the type implements a Close method

	//when you want to block for shutdown signals
	death.WaitForDeath(objects...) // this will finish when a signal of your type is sent to your application
}

type NewType struct {
}

func (c *NewType) Close() error {
	return nil
}
Or close using an anonymous function
package main

import (
	DEATH "github.com/vrecan/death"
	SYS "syscall"
)

func main() {
	death := DEATH.NewDeath(SYS.SIGINT, SYS.SIGTERM) //pass the signals you want to end your application
	//when you want to block for shutdown signals
	death.WaitForDeathWithFunc(func(){ 
		//do whatever you want on death
	}) 
}

Documentation ¶

Rendered for

Index ¶

  • type Death
    • func NewDeath(signals ...os.Signal) (death *Death)
    • func (d *Death) FallOnSword()
    • func (d *Death) SetLogger(l Logger)
    • func (d *Death) SetTimeout(t time.Duration)
    • func (d *Death) WaitForDeath(closable ...io.Closer)
    • func (d *Death) WaitForDeathWithFunc(f func())
  • type Logger

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type Death ¶

type Death struct {
	// contains filtered or unexported fields
}

Death manages the death of your application.

func NewDeath ¶

func NewDeath(signals ...os.Signal) (death *Death)

NewDeath Create Death with the signals you want to die from.

func (*Death) FallOnSword ¶

func (d *Death) FallOnSword()

FallOnSword manually initiates the death process.

func (*Death) SetLogger ¶

func (d *Death) SetLogger(l Logger)

SetLogger Overrides the default logger (seelog)

func (*Death) SetTimeout ¶

func (d *Death) SetTimeout(t time.Duration)

SetTimeout Overrides the time death is willing to wait for a objects to be closed.

func (*Death) WaitForDeath ¶

func (d *Death) WaitForDeath(closable ...io.Closer)

WaitForDeath wait for signal and then kill all items that need to die.

func (*Death) WaitForDeathWithFunc ¶

func (d *Death) WaitForDeathWithFunc(f func())

WaitForDeathWithFunc allows you to have a single function get called when it's time to kill your application.

type Logger ¶

type Logger interface {
	Error(v ...interface{}) error
	Debug(v ...interface{})
	Info(v ...interface{})
	Warn(v ...interface{}) error
}

Logger interface to log.

Source Files ¶

View all Source files
  • death.go
Click to show internal directories.
Click to hide internal directories.
You are visitor 01402877 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.