Product Promotion
0x5a.live
for different kinds of informations and explorations.
GitHub - sinhashubham95/bleep: OS Signal Handlers in Go
OS Signal Handlers in Go. Contribute to sinhashubham95/bleep development by creating an account on GitHub.
Visit SiteGitHub - sinhashubham95/bleep: OS Signal Handlers in Go
OS Signal Handlers in Go. Contribute to sinhashubham95/bleep development by creating an account on GitHub.
Powered by 0x5a.live ๐
Bleep
Bleep
is used to peform actions on OS signals. It is highly extensible and goroutine safe. It is possible to add any number of actions and all of them are guaranteed to be performed simultaneously on the OS signals that Bleep
will be listening for.
Installation
go get github.com/sinhashubham95/bleep
How to Use
The Bleep
package allows you to create a new instance of the handler and also has a default handler in place that can be used directly.
Creating separate Bleep instances can be useful, when you want to perform different set of actions for different set of OS signals.
Create a New OS Signal Handler
This is used to create a new handler for performing actions on OS Signals.
import (
"os"
"github.com/sinhashubham95/bleep"
)
func New() {
handler := bleep.New()
// now this handler can be used to add or remove actions and listen to the OS signals
}
Add an Action
This is used to add an action to be executed on the OS signal listening for.
import (
"os"
"github.com/sinhashubham95/bleep"
)
fun Add() {
key := bleep.Add(func (s os.Signal) {
// do something
})
// this key is the unique identifier for your added action
}
Remove an Action
This is used to remove an action added to Bleep.
import (
"github.com/sinhashubham95/bleep"
)
func Remove() {
action := bleep.Remove("some-key") // this key should be the same as the one returned during adding the action
// the returned action is the one that was added using this key
}
Listen
This is used to listen for the OS signals. Note that this will wait for the signal in the go routine in which this is called.
import (
"syscall"
"github.com/sinhashubham95/bleep"
)
func Listen() {
bleep.Listen(syscall.SIGINT, syscall.SIGTERM)
}
GoLang Resources
are all listed below.
Made with โค๏ธ
to provide different kinds of informations and resources.