Use defer

This commit is contained in:
Julian Kornberger 2016-10-04 00:50:39 +02:00
parent 75228cf8bf
commit a60be980c5
1 changed files with 3 additions and 10 deletions

13
main.go
View File

@ -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()
}