Skip to content

Commit

Permalink
Let ES Persist return error on failure
Browse files Browse the repository at this point in the history
bittersweet committed Oct 11, 2015
1 parent 2e69267 commit c8e8844
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions elasticsearch/client.go
Original file line number Diff line number Diff line change
@@ -16,9 +16,8 @@ type ESPayload struct {
Data map[string]interface{} `json:"data"`
}

func Persist(key string, data map[string]interface{}) {
fmt.Println("Printing from ES Package: ", key)
fmt.Println("Printing from ES Package: ", data)
func Persist(key string, data map[string]interface{}) error {
fmt.Printf("[ES] Persisting to %s: %v\n", key, data)

payload := ESPayload{
Key: key,
@@ -28,12 +27,14 @@ func Persist(key string, data map[string]interface{}) {
body, _ := json.Marshal(payload)
resp, err := http.Post("http://localhost:9200/notifilter/event/?pretty", "application/json", bytes.NewReader(body))
if err != nil {
log.Fatal(err)
return err
}
defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
return err
}
log.Print(string(body))
log.Println("[ES] Success")
log.Println("[ES]", string(body))
return nil
}

0 comments on commit c8e8844

Please sign in to comment.