Skip to content

Commit

Permalink
deserialize Failures in BaseResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Dec 9, 2014
1 parent 9851a15 commit e5fad29
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/baseresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ package elastigo

import (
"encoding/json"
"fmt"
"strconv"
"strings"
)

type BaseResponse struct {
Expand Down Expand Up @@ -86,6 +88,29 @@ type Status struct {
Total StatusInt `json:"total"`
Successful StatusInt `json:"successful"`
Failed StatusInt `json:"failed"`
Failures []Failure `json:"failures,omitempty"`
}

type Failure struct {
Index string `json:"index"`
Shard StatusInt `json:"shard"`
Reason string `json:"reason"`
}

func (f Failure) String() string {
return fmt.Sprintf("Failed on shard %d on index %s:\n%s", f.Shard, f.Index, f.Reason)
}

// failures is a convenience type to allow []Failure formated easily in the
// library
type failures []Failure

func (f failures) String() string {
message := make([]string, len(f))
for i, failure := range f {
message[i] = failure.String()
}
return strings.Join(message, "\n")
}

type ExtendedStatus struct {
Expand Down

0 comments on commit e5fad29

Please sign in to comment.