Documentation
¶
Overview ¶
Package sigmon simplifies os.Signal handling.
Example ¶
package main import ( "github.com/codemodus/sigmon" ) func main() { sm := sigmon.New(nil) sm.Run() // Do things which cannot be affected by OS signals... sm.Set(signalHandler) // Do things which can be affected by OS signals... sm.Set(nil) // Do more things which cannot be affected by OS signals... sm.Stop() // OS signals will be handled normally. } func signalHandler(sm *sigmon.SignalMonitor) { }
Example (PassingContext) ¶
sigCtx := &signalContext{id: 123} // The setOutput method stores the signal type when any signal is handled. sm := sigmon.New(sigCtx.setOutput) sm.Run() // Simulate a system signal (windows does not support self-signaling). if err := callOSSignal(syscall.SIGINT); err != nil { fmt.Fprintln(os.Stderr, err) } sm.Stop() // The output method returns the called signal type and sigCtx.id value. fmt.Println(sigCtx.output())
Output: INT 123
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Signal ¶
type Signal string
Signal wraps the string type to reduce confusion when checking Sig.
type SignalMonitor ¶
SignalMonitor helps manage signal handling.
func New ¶
func New(handler func(*SignalMonitor)) (s *SignalMonitor)
New takes a function and returns a SignalMonitor. When a nil arg is provided, no action will be taken during signal handling. Run must be called in order to begin handling.
func (*SignalMonitor) Set ¶
func (m *SignalMonitor) Set(handler func(*SignalMonitor))
Set allows the handler function to be added or removed. If no function has been provided, no action will be taken during signal handling. Only the most recently passed function holds any effect.
func (*SignalMonitor) Sig ¶
func (m *SignalMonitor) Sig() Signal
Sig returns a typed string (Signal) representing the most recently called os.Signal.
func (*SignalMonitor) Stop ¶
func (m *SignalMonitor) Stop()
Stop discontinues all os.Signal handling.