From a60be980c509c40007db7b30853a90b085d33697 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Tue, 4 Oct 2016 00:50:39 +0200 Subject: [PATCH] Use defer --- main.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index fcffe3b..bf2229b 100644 --- a/main.go +++ b/main.go @@ -37,10 +37,11 @@ func main() { if config.Influxdb.Enable { db = database.New(config) + defer db.Close() if importPath != "" { importRRD(importPath) - os.Exit(0) + return } } @@ -48,6 +49,7 @@ func main() { if config.Respondd.Enable { collectInterval := time.Second * time.Duration(config.Respondd.CollectInterval) collector = respond.NewCollector(db, nodes, collectInterval, config.Respondd.Interface) + defer collector.Close() } if config.Webserver.Enable { @@ -73,14 +75,6 @@ func main() { signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) sig := <-sigs log.Println("received", sig) - - // Close everything at the end - if collector != nil { - collector.Close() - } - if db != nil { - db.Close() - } } func importRRD(path string) { @@ -96,5 +90,4 @@ func importRRD(path string) { ds.Time, ) } - db.Close() }