replace pannic with fmt.Errorf in elasticsearch storage

This commit is contained in:
wangzhezhe 2016-01-04 13:15:16 +08:00
parent 0367672b9e
commit 95a6e4e87c

View File

@ -103,7 +103,8 @@ func (self *elasticStorage) AddStats(ref info.ContainerReference, stats *info.Co
Do() Do()
if err != nil { if err != nil {
// Handle error // Handle error
panic(fmt.Errorf("failed to write stats to ElasticSearch- %s", err)) fmt.Errorf("failed to write stats to ElasticSearch - %s", err)
return
} }
}() }()
return nil return nil
@ -135,14 +136,15 @@ func newStorage(
) )
if err != nil { if err != nil {
// Handle error // Handle error
panic(err) return nil, fmt.Errorf("failed to create the elasticsearch client - %s", err)
} }
// Ping the Elasticsearch server to get e.g. the version number // Ping the Elasticsearch server to get e.g. the version number
info, code, err := client.Ping().URL(elasticHost).Do() info, code, err := client.Ping().URL(elasticHost).Do()
if err != nil { if err != nil {
// Handle error // Handle error
panic(err) return nil, fmt.Errorf("failed to ping the elasticsearch - %s", err)
} }
fmt.Printf("Elasticsearch returned with code %d and version %s", code, info.Version.Number) fmt.Printf("Elasticsearch returned with code %d and version %s", code, info.Version.Number)