cmd

package
v0.0.0-...-27b3b18 Latest Latest
Warning

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

Go to latest
Published: May 20, 2025 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusOK     status = 0   // StatusOK stores ok status code.
	StatusErr    status = 1   // StatusErr stores catchall error status code.
	StatusErrArg status = 2   // StatusErrArg stores arg error status code.
	StatusHup    status = 129 // StatusHup stores hangup status code.
	StatusInt    status = 130 // StatusInt stores interrupt status code.
	StatusQuit   status = 131 // StatusQuit stores quit status code.
	StatusTerm   status = 143 // StatusTerm stores terminate status code.
)

STANDARDS

Variables

View Source
var (
	// ErrHup means hangup signal.
	ErrHup = errors.New("cmd: received hangup signal")

	// ErrInt means interrupt signal.
	ErrInt = errors.New("cmd: received interrupt signal")

	// ErrQuit means quit signal.
	ErrQuit = errors.New("cmd: received quit signal")

	// ErrTerm means terminate signal.
	ErrTerm = errors.New("cmd: received terminate signal")
)
View Source
var (
	// ErrLockExists means lockfile exists.
	ErrLockExists = errors.New("cmd: lockfile exists")

	// ErrLockCreate means lock err.
	ErrLockCreate = errors.New("cmd: lockfile create error")

	// ErrLockDel means lockfile del error.
	ErrLockDel = errors.New("cmd: lockfile delete error")
)
View Source
var (
	StatusHit status = 166                    // StatusHit stores hit status code.
	ErrHit           = errors.New("cmd: hit") // ErrHit stores hit error.
)

CUSTOMS 166 - 199

Functions

func Exit

func Exit(state *State, err error)

Exit exits. The status code is set. All goroutine cancel fns are run for clean exit.

func Listen

func Listen(state *State) error

Listen listens for proc ending signal events. A suitable exit code is then applied as final responsibility.

func SetStatus

func SetStatus(state *State, err error)

SetStatus sets the status code.

Types

type Cancel

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

Cancel represents cancel fns.

func (*Cancel) Add

func (cancel *Cancel) Add(fn context.CancelFunc)

Add adds a given cancel fn.

type State

type State struct {
	Exit     status
	Lockfile string
	Signal   chan os.Signal `json:"-"`
	Cancel   *Cancel        `json:"-"`
}

State represents proc state. Cancel stores goroutine cancel fns.

func NewState

func NewState() *State

NewState returns a new app state.

func (*State) AddCancel

func (state *State) AddCancel(fn context.CancelFunc)

AddCancel adds a given cancel fn.

func (*State) CancelAll

func (state *State) CancelAll()

CancelAll runs stored cancel fns.

func (*State) GetCancels

func (state *State) GetCancels() []context.CancelFunc

GetCancels returns cancel fns, then clears them.

func (*State) Lock

func (state *State) Lock(path string) error

Lock checks exclusivity to create the lockfile if available.

Jump to

Keyboard shortcuts

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