type check

This commit is contained in:
Nan Deng 2014-07-02 16:20:05 -07:00
parent 84fefcdab9
commit 4115f73343

View File

@ -193,8 +193,12 @@ func (self *influxdbStorage) valuesToContainerStats(columns []string, values []i
stats.Timestamp, err = time.Parse(time.RFC3339Nano, str) stats.Timestamp, err = time.Parse(time.RFC3339Nano, str)
} }
case col == colMachineName: case col == colMachineName:
if v.(string) != self.machineName { if m, ok := v.(string); ok {
return nil, fmt.Errorf("different machine") if m != self.machineName {
return nil, fmt.Errorf("different machine")
}
} else {
return nil, fmt.Errorf("machine name field is not a string: %v", v)
} }
// Cumulative Cpu Usage // Cumulative Cpu Usage
case col == colCpuCumulativeUsage: case col == colCpuCumulativeUsage:
@ -254,8 +258,12 @@ func (self *influxdbStorage) valuesToContainerSample(columns []string, values []
sample.Timestamp, err = time.Parse(time.RFC3339Nano, str) sample.Timestamp, err = time.Parse(time.RFC3339Nano, str)
} }
case col == colMachineName: case col == colMachineName:
if v.(string) != self.machineName { if m, ok := v.(string); ok {
return nil, fmt.Errorf("different machine") if m != self.machineName {
return nil, fmt.Errorf("different machine")
}
} else {
return nil, fmt.Errorf("machine name field is not a string: %v", v)
} }
// Memory Usage // Memory Usage
case col == colMemoryUsage: case col == colMemoryUsage: