10func NewSqliteConnection(dbPath string) *sql.DB {
11 db, err := sql.Open("sqlite3", dbPath)
12 if err != nil {
13 log.Fatal(err)14 }
15 return db
16}
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)
}
}