41 ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
42 r.Shutdown(ctx)
43
44 os.Exit(0)45}
46
47func usage() {
48 fmt.Fprintf(os.Stderr, "usage: generate <controllers|routes>\n")
49 os.Exit(1)50}
43 ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
44 s.Shutdown(ctx)
45
46 os.Exit(0)47}
Packages exposing functions that can stop program execution by exiting are hard to reuse. Program exits in functions other than main() or init() are not encouraged.
func nonMainFunc() {
safelyExit := true // somehow arrive at this value
if safelyExit {
os.Exit(0)
}
}
func main() {
nonMainFunc()
}
func nonMainFunc() bool {
safelyExit := true // somehow arrive at this value
}
func main() {
safelyExit := nonMainFunc()
if safelyExit {
os.Exit(0)
}
}