die: linter feedback fixes.
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
Simple fatal utilities for Go programs.
|
||||
|
||||
```
|
||||
result, err := doSomething()
|
||||
die.If(err)
|
||||
|
||||
ok := processResult(result)
|
||||
if !ok {
|
||||
die.With("failed to process result %s", result.Name)
|
||||
}
|
||||
```
|
||||
|
||||
11
die/die.go
11
die/die.go
@@ -1,4 +1,5 @@
|
||||
// Package die contains utilities for fatal error handling.
|
||||
// Package die contains utilities for fatal error handling. It
|
||||
// presents simple fatal utilities for Go programs.
|
||||
package die
|
||||
|
||||
import (
|
||||
@@ -15,15 +16,15 @@ func If(err error) {
|
||||
}
|
||||
|
||||
// With prints the message to stderr, appending a newline, and exits.
|
||||
func With(fstr string, args ...interface{}) {
|
||||
func With(fstr string, args any) {
|
||||
out := fmt.Sprintf("[!] %s\n", fstr)
|
||||
fmt.Fprintf(os.Stderr, out, args...)
|
||||
fmt.Fprintf(os.Stderr, out, args)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// When prints the error to stderr and exits if cond is true.
|
||||
func When(cond bool, fstr string, args ...interface{}) {
|
||||
func When(cond bool, fstr string, args any) {
|
||||
if cond {
|
||||
With(fstr, args...)
|
||||
With(fstr, args)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user