diff options
| author | Jeff Carr <[email protected]> | 2025-10-17 05:36:18 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-17 05:36:18 -0500 |
| commit | 555c8cd918b1253723464604d6871185991e5edc (patch) | |
| tree | 2d1aabdc97047005e75bc505fd1fe8936524522d /exit.go | |
| parent | 6294b7b53c94fa77ac8ef3ba466b1cf032bdc6a8 (diff) | |
rename files to help organize my thoughts
Diffstat (limited to 'exit.go')
| -rw-r--r-- | exit.go | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/exit.go b/exit.go deleted file mode 100644 index 1419ae2..0000000 --- a/exit.go +++ /dev/null @@ -1,75 +0,0 @@ -package argvpb - -import ( - "fmt" - "os" - "time" - - "go.wit.com/lib/cobol" - "go.wit.com/log" -) - -// since we know when the command starts (duh, this parses os.Args) -// this is a convienent way to provide a standard exit format back -// to the shell that also has built in timing! - -// also, it supports a custom Exit() back to your application - -func (pb *Argv) GoodExit(msg string) { - go ExitWatchdog() - if me.appExit != nil { - me.appExit() - } - dur := time.Since(pb.Ctime.AsTime()) - log.Infof("%s: %s (%s)\n", pb.Argname, msg, cobol.FormatDuration(dur)) - os.Exit(0) -} - -func (pb *Argv) BadExit(msg string, err error) { - go ExitWatchdog() - if me.appExit != nil { - me.appExit() - } - // print out errors. this handles wrapped errors which is a useful - if err != nil { - if u, ok := err.(interface{ Unwrap() []error }); ok { - // If it does, call the method to get the slice of errors. - allerr := u.Unwrap() - for _, e := range allerr { - log.Info("Error:", e) - } - } else { - // If it's not a joined error, you can fall back to the single-unwrap loop. - log.Info("Error:", err) - } - } - - dur := time.Since(pb.Ctime.AsTime()) - log.Infof("%s error: %s (%s)\n", pb.Argname, msg, cobol.FormatDuration(dur)) - os.Exit(1) -} - -// this code doesn't need to be this complicated. I put it here as reference code for myself so I could remember where it is. -func ExitWatchdog() { - dog := time.NewTicker(5 * time.Second) - defer dog.Stop() - dogchan := make(chan bool) - /* - // this example would exit/destroy the ticker in 10 seconds - go func() { - time.Sleep(10 * time.Second) - done <- true - }() - */ - for { - select { - case <-dogchan: - fmt.Println("Done!") - return - case t := <-dog.C: - _ = t - log.Info("argv.Exit() watchdog: stalled in", me.ARGNAME+".Exit()") - // h.Scan() - } - } -} |
