Use defer
This commit is contained in:
parent
75228cf8bf
commit
a60be980c5
13
main.go
13
main.go
@ -37,10 +37,11 @@ func main() {
|
|||||||
|
|
||||||
if config.Influxdb.Enable {
|
if config.Influxdb.Enable {
|
||||||
db = database.New(config)
|
db = database.New(config)
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
if importPath != "" {
|
if importPath != "" {
|
||||||
importRRD(importPath)
|
importRRD(importPath)
|
||||||
os.Exit(0)
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ func main() {
|
|||||||
if config.Respondd.Enable {
|
if config.Respondd.Enable {
|
||||||
collectInterval := time.Second * time.Duration(config.Respondd.CollectInterval)
|
collectInterval := time.Second * time.Duration(config.Respondd.CollectInterval)
|
||||||
collector = respond.NewCollector(db, nodes, collectInterval, config.Respondd.Interface)
|
collector = respond.NewCollector(db, nodes, collectInterval, config.Respondd.Interface)
|
||||||
|
defer collector.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Webserver.Enable {
|
if config.Webserver.Enable {
|
||||||
@ -73,14 +75,6 @@ func main() {
|
|||||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||||
sig := <-sigs
|
sig := <-sigs
|
||||||
log.Println("received", sig)
|
log.Println("received", sig)
|
||||||
|
|
||||||
// Close everything at the end
|
|
||||||
if collector != nil {
|
|
||||||
collector.Close()
|
|
||||||
}
|
|
||||||
if db != nil {
|
|
||||||
db.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func importRRD(path string) {
|
func importRRD(path string) {
|
||||||
@ -96,5 +90,4 @@ func importRRD(path string) {
|
|||||||
ds.Time,
|
ds.Time,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
db.Close()
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user