1
0
mirror of https://github.com/Oxalide/vsphere-influxdb-go.git synced 2023-10-10 13:36:51 +02:00

Only defer client.Logout if client has been successfully returned.

This commit is contained in:
Lucas Y.Z. Zhang 2016-09-08 17:40:49 +08:00
parent 482da3d2b9
commit 50c45f7d2a

View File

@ -131,12 +131,12 @@ func (vcenter *VCenter) Init(config Configuration) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client, err := vcenter.Connect()
defer client.Logout(ctx)
if err != nil {
errlog.Println("Could not connect to vcenter: ", vcenter.Hostname)
errlog.Println("Error: ", err)
return
}
defer client.Logout(ctx)
var perfmanager mo.PerformanceManager
err = client.RetrieveOne(ctx, *client.ServiceContent.PerfManager, nil, &perfmanager)
if err != nil {
@ -182,12 +182,12 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
// Get the client
client, err := vcenter.Connect()
defer client.Logout(ctx)
if err != nil {
errlog.Println("Could not connect to vcenter: ", vcenter.Hostname)
errlog.Println("Error: ", err)
return
}
defer client.Logout(ctx)
// Create the view manager
var viewManager mo.ViewManager