Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/renanbastos93/ossignals
This package helps us to use signals in Golang
https://github.com/renanbastos93/ossignals
Last synced: 18 days ago
JSON representation
This package helps us to use signals in Golang
- Host: GitHub
- URL: https://github.com/renanbastos93/ossignals
- Owner: renanbastos93
- License: mit
- Created: 2022-04-08T00:17:53.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-04-08T01:47:31.000Z (over 2 years ago)
- Last Synced: 2024-10-05T16:41:27.491Z (about 1 month ago)
- Language: Go
- Size: 2.93 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ossignals-go
This package helps us to use signals in Golang## How to install
```bash
$ go install github.com/renanbastos93/ossignals
```## How to use
```go
package mainimport (
"fmt"
"os"
"syscall""github.com/renanbastos93/ossignals"
)func main() {
// Show PID to you can send signals for thread main of this app
fmt.Println("PID:", os.Getpid())// Create a new thread to listen signals received by operation system
go ossignals.On(// Create actions to each signal
ossignals.Actions{
syscall.SIGTERM: func() bool {
fmt.Println("I'm dying...")
return true
},
syscall.SIGHUP: func() bool {
// Here we can do reload a config, reload connections, or anything...
fmt.Println("process anything...")
return false
},
syscall.SIGINT: func() bool {
fmt.Println("close by CTRL + C")
return true
},
},
)
// When receiving true in the function defined in your actions thread main is finished.
<-ossignals.Close
}
```Case you don't know about signals in the operating system you can [read this doc.](https://man7.org/linux/man-pages/man7/signal.7.html)