mirror of
https://github.com/hairyhenderson/go-onerng.git
synced 2025-04-04 17:50:12 -05:00
37 lines
529 B
Go
37 lines
529 B
Go
// onerng: OneRNG hardware random number generation utility
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
)
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
c := make(chan os.Signal, 1)
|
|
signal.Notify(c, os.Interrupt)
|
|
defer func() {
|
|
signal.Stop(c)
|
|
cancel()
|
|
}()
|
|
go func() {
|
|
select {
|
|
case <-c:
|
|
cancel()
|
|
case <-ctx.Done():
|
|
}
|
|
}()
|
|
|
|
cmd := rootCmd(ctx)
|
|
initConfig(ctx, cmd)
|
|
if err := cmd.Execute(); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|